[R] Loops that last for ever...

Constantine Tsardounis costas.magnuse at gmail.com
Tue Jan 31 01:04:58 CET 2006


Thank you very much!!!  It works!.. I will try your philosophy to my script!...

xs <- lapply(1:500,  function(x) rnorm(1000))
result <- lapply(xs, function(.val){
    .total <- sum(.val)   # total sum
    .sums <- filter(.val, rep(1,5)) # sum 5 consective values
    list(total=.total, sum=.sums[-c(1,2,length(.sums)-1, length(.sums))])}
)
# create lists of sum and totals
total <- lapply(result, '[[', 'total')
sums <- lapply(result, '[[', 'sum')




More information about the R-help mailing list