I think the results are different, because length in matrix (i.e. cbind(Apple, HP, Microsoft) and length in each list element does not match
cov.pop <- function(x,y=NULL) { cov(x,y)*(NROW(x)-1)/NROW(x) }
Using an example dataset
set.seed(24) Apple <- rnorm(140) HP <- rnorm(140) Microsoft <- rnorm(140) cov.pop(cbind(Apple,HP,Microsoft)) # Apple HP Microsoft #Apple 0.946489639 0.006511604 0.02518080 #HP 0.006511604 1.015532869 0.04940075 #Microsoft 0.025180805 0.049400745 1.08388185 sapply(list(Apple,HP,Microsoft),cov.pop,y=Apple) #[1] 0.946489639 0.006511604 0.025180805 sapply(list(Apple,HP,Microsoft),cov.pop,y=HP) #[1] 0.006511604 1.015532869 0.049400745 sapply(list(Apple,HP,Microsoft),cov.pop,y=Microsoft) #[1] 0.02518080 0.04940075 1.08388185
akrun
source share