I have two different lists (a and b) containing 626257 vectors, each vector containing 44 numeric entries. One list contains sample data and the other list serves as a reference. Now I want to calculate the pearson correlation between all the entries of both lists. I store the values in a variable (r).
The output of "r" does unfortunately only contain "NA" entries.
Here the code to generate two dummy lists.
a = replicate(626257,rep(10,44),simplify = FALSE)
b = replicate(626257,rep(3,44),simplify = FALSE)
And here the code to calculate the correlation.
r = lapply(seq_along(a), function(ind)cor(a[[ind]], b[[ind]]))
View(r)
You can use mapply
to complete this task pretty easily. As AkselA pointed out, you first need to simulate data with some variance (using rnorm(44)
instead of rep, 10, 44)
for example). See below:
a <- replicate(626257,rnorm(44),simplify = FALSE)
b <- replicate(626257,rnorm(44),simplify = FALSE)
r <- mapply(cor, a, b)