Hi, 
How can I accomplish this in R. Example:  

I have the following data.frame:

data <- 
data.frame(x=c(1,2,3,4,5,6,5,3,7,1,0,4,8),y=c(1,2,1,2,2,2,1,1,1,2,2,2,2),z=c(5,8,4,3,4,1,6,3,3,6,3,5,7))

Supposing that data$y is a factor, I would like to find the Spearman 
correlation between data$x and data$z indexing it by data$y. 
To be more specific, I want to find two correlations: between x and z with y==1 
and the same correlation with x and z where y==2.
Something like:

cor(data$x[data$y==1],data$z[data$y==1],method= "spearman") and 
cor(data$x[data$y==2],data$z[data$y==2],method= "spearman"),

but without having to write all the values for data$y and use cor more than 
once.

I hope I made myself clear.
Thanks
Mateus


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to