Reputation: 205
I used the following code to get an entire table of Spearman Rho correlations in R from a CSV file with only 1 data type (numbers):
> myDataset <- read.csv(file.choose())
> attach(myDataset)
> spearmanRhoTable <- cor(myDataset, use="complete.obs",method="spearman")
Is there any way I could take my table of r-values (spearmanRhoTable) and get a table of all the p-values, rather than having to enter each Spearman correlation manually to get individual p-values?
Here is my table of r-values. It's called spearmanRhoTable, and I was wondering if there was a quick way to get p-values for everything in this table.
Upvotes: 1
Views: 1877
Reputation: 8711
The Hmisc
package has a function rcorr
that can give you a matrix of p-values.
library(Hmisc)
df <- data.frame(x = runif(10),
y = runif(10),
z = runif(10))
rcorr(as.matrix(df))$P
Upvotes: 1