Supposedly I have two dataframes, which include a number of NAs:
DF1=data.frame(a=c(20,70,50,NA),b=c(40,90,30,20),c=c(60,110,NA,40))
DF2=data.frame(e=c(200,700,NA,400),f=c(400,900,500,200),g=c(600,1100,NA,700))
I'd still like to correlate the rows in those two, while giving out NA if one of the values in a correlated pair is already a NA. Tried a for-loop:
for (M in 1:nrow(DF1)) {
Test=cor(DF1[M,],DF2[M,],use="na.or.complete")
print(Test)
}
... which gave me this:
e f g
a NA NA NA
b NA NA NA
c NA NA NA
e f g
a NA NA NA
b NA NA NA
c NA NA NA
e f g
a NA NA NA
b NA NA NA
c NA NA NA
e f g
a NA NA NA
b NA NA NA
c NA NA NA
What am I doing wrong?