[R] appending to a vector

From: dirknbr <dirknbr_at_gmail.com>
Date: Thu, 14 Apr 2011 01:59:04 -0700 (PDT)


Which one is more efficient?

x2=c()
for (i in 1:length(x)) {
 x2=c(x2,func(x[i]))
}

or

x2=x
for (i in 1:length(x)) {
 x2=func(x[i])
}

where func is any function?

Dirk

--
View this message in context: http://r.789695.n4.nabble.com/appending-to-a-vector-tp3449109p3449109.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.
Received on Thu 14 Apr 2011 - 15:38:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 14 Apr 2011 - 16:40:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive