rg wrote on 04/14/2011 04:59:04 AM:
> [image removed]
>
> [R] appending to a vector
>
> dirknbr
>
> to:
>
> r-help
>
> 04/14/2011 11:32 AM
>
> Sent by:
>
> r-help-boun...@r-project.org
>
> Which one is more efficient?
>
> x2=c()
&
Hi Dirk,
On Thu, Apr 14, 2011 at 4:59 AM, dirknbr wrote:
> 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?
This one. Creating a [vector|matrix|dataframe]
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
3 matches
Mail list logo