Hi r-users,
 
I have this code here, but I just wonder how do I use 'sapply' to make it more 
efficient

lamda_cor <- eigen(winter_cor)$values
 
> lamda_cor
[1] 1.3459066 1.0368399 0.8958128 0.7214407
 
lamda_cxn <- function(dt)
{ n       <- length(dt)
  term    <- vector(length=n, mode="numeric")
  
  for (i in 1:n)
  { term[i] <- (dt[i]/n)*log(dt[i]/n) }
 
  #sum(term)
  cxn <- 1 + (1/log(n))*sum(term)
  cxn
}
lamda_cxn(lamda_cor)
> lamda_cxn(lamda_cor)
[1] 0.01861457
 
Thank you so much for all helps given.

 


      
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to