Correlate item in dataframe based on character string in r -


i have dataset newdat, dataframe containing item scores:

set.seed(1) newdat <- setnames(data.frame(replicate(5,sample(1:5,10,replace=true))),paste0("i",1:5))     i1 i2 i3 i4 i5 1   2  2  5  3  5 2   2  1  2  3  4 3   3  4  4  3  4 4   5  2  1  1  3 5   2  4  2  5  3 6   5  3  2  4  4 7   5  4  1  4  1 8   4  5  2  1  3 9   4  2  5  4  4 10  1  4  2  3  4 

i have character strings "newcv" , "newdv" are:

newcv <- c("i3","i2") newdv <- c("i1") 

i attempting correlate dv of items except itself, , items contained in newcv. have tried following:

corr<-cor(newdat,use="complete.obs")[-which(colnames(newdat)==c(newcv,newdv)),which(colnames(newdat)==c(newcv,newdv))] 

which works if there nothing found in cv, if there in cv error , no results. thoughts? thank you!

if want calculate specific correlations can select columns pass cor

cor(newdat[newdv], newdat[!(names(newdat) %in% c(newcv, newdv))],                                                        use="complete.obs") 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -