r - Using ddply instead of for -


i'm quite new plyr package (and r in general) have following code

# have dataframe df  # columns:  #     -somefactor: factor #     -value:      numeric  f<-levels(df$somefactor) k<-length(f) m<-mat.or.vec(k,k) for(i in 1:k) {   (j in 1:k)     m[i,j]=cor(df[somefactor==f[i],]$value,df[somefactor==f[j],]$value) } 

how simplify code using ddply function (or similar, remove ugly cycles

thank lot!

fida

you can try :

cor(as.data.frame(split(df$value, df$somefactor))) 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -