[R] Question on creating list object

megh megh700004 at yahoo.com
Mon Nov 17 11:00:16 CET 2008


I get following result, while I write this code :

> lapply(1:5, function(i) c(1,2,3)^i)
[[1]]
[1] 1 2 3

[[2]]
[1] 1 4 9

[[3]]
[1]  1  8 27

[[4]]
[1]  1 16 81

[[5]]
[1]   1  32 243

This is fine. However my goal is : each element of this list should depend
on previous element like :

lis # List name
then,

lis[[i]] = lis[[i-1]] + c(1,2,3)^i

How can I modify my current code without having a "for" loop ?

Regards,
-- 
View this message in context: http://www.nabble.com/Question-on-creating-list-object-tp20536658p20536658.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list