Can't you use sapply? sapply(seq_len(10), function(i){SomeExpression(i)})
Best regards, Thierry > -----Oorspronkelijk bericht----- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > Namens David Winsemius > Verzonden: woensdag 10 augustus 2011 15:50 > Aan: Anthony Ching Ho Ng > CC: r-help@r-project.org > Onderwerp: Re: [R] rbind/cbind > > > On Aug 10, 2011, at 9:08 AM, Anthony Ching Ho Ng wrote: > > > Dear list, > > > > I wonder if there a better way to have rbind/cbind/append to create > > the first element (if it is empty) instead of doing the following in a > > loop? > > > > for (i in 1:10) { > > if (i == 1) { > > aRow = SomeExpression(i) > > } else { > > aRow = rbind(aRow,SomeExpression(i)) } } > > > > Generally one is advised not to use rbind in this manner but rather to pre- > allocate aRow to the size needed and then to add information by rows using > "[". > > For a matrix this might be: > > aRow <- matrix(NA, ncol=3, nrow=10) > > for (i in 1:10) { > aRow[1,] <- SomeExpression(i) > } > > > -- > David Winsemius, MD > West Hartford, CT > > ______________________________________________ > 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. ______________________________________________ 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.