Try this:

1 + (1 / log(length(lambda_cor))) * sum((l <- lambda_cor /
length(lambda_cor)) * log(l))


On Sun, May 16, 2010 at 10:43 PM, Roslina Zakaria <zroslina@yahoo.com>wrote:

> 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.
>
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

