Domanda

With the code below I have created a correlation matrix. The code below just creates a matrix for all of the data, regardless of treatment. However, a column in my data is treatment. I would like to make two different matrices (one for each treatment type). My treatment a categorical value in column 6 'Treat'. Columns 10 through 44 I would like to create a matrix for.

correlations <- cor(Plants[,c(10:44)], use="pairwise.complete.obs", method="pearson")
correlations<-as.matrix(correlations) 
È stato utile?

Soluzione

If you have just two treatment categories then you can make two separate analysis for each level (selecting the data just for particular level). Just replace names Treatment1 and Treatment2 with actual names of your treatments.

kor1<-cor(Plants[Plants$Treat=="Treatment1",c(10:44)], use="pairwise.complete.obs", method="pearson")
kor2<-cor(Plants[Plants$Treat=="Treatment2",c(10:44)], use="pairwise.complete.obs", method="pearson")

Altri suggerimenti

You could use by to apply a function to different subsets of your data.

by(Plants[10:44], Plants["Treat"],
   cor, use = "pairwise.complete.obs", method = "pearson")
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top