Displaying 1 result from an estimated 1 matches for "lamda_cxn".
Did you mean:
lamda_cor
2010 May 17
1
sapply code
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 y...