Can anyone please tell me how to define a "list". Suppose I want to define a list object "result" with length n then want to fill each place of "result" with different objects. For e.g. i=1 result[1] = rnorm(1) i=2 result[2] = rnorm(2) ....................... i=n result[n] = rnorm(n) What would be the best way to do that? Regards,
Try this: lapply(1:n, rnorm) On Wed, Oct 15, 2008 at 8:19 AM, Megh Dal <megh700004@yahoo.com> wrote:> Can anyone please tell me how to define a "list". Suppose I want to define > a list object "result" with length n then want to fill each place of > "result" with different objects. For e.g. > > i=1 > result[1] = rnorm(1) > > i=2 > result[2] = rnorm(2) > > ....................... > > i=n > result[n] = rnorm(n) > > What would be the best way to do that? > > Regards, > > ______________________________________________ > 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]]
maybe: result <- list() for (i in 1:10) result[[i]] <- rnorm(i) Bart Megh Dal wrote:> > Can anyone please tell me how to define a "list". Suppose I want to define > a list object "result" with length n then want to fill each place of > "result" with different objects. For e.g. > > i=1 > result[1] = rnorm(1) > > i=2 > result[2] = rnorm(2) > > ....................... > > i=n > result[n] = rnorm(n) > > What would be the best way to do that? > > Regards, > > ______________________________________________ > R-help at 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. > >-- View this message in context: http://www.nabble.com/Defining-a-%22list%22-tp19991526p19994922.html Sent from the R help mailing list archive at Nabble.com.