[R] A More efficient method?

Stefan Grosse singularitaet at gmx.net
Wed Jul 4 18:03:27 CEST 2007


Gabor Grothendieck wrote:
>> set.seed(1)
>> C <- sample(c("a", "b"), 100000, replace = TRUE)
>> system.time(s1 <- ifelse(C == "a", 1, -1))
>>     
>    user  system elapsed
>    0.37    0.01    0.38
>   
>> system.time(s2 <- 2 * (C == "a") - 1)
>>     
>    user  system elapsed
>    0.02    0.00    0.02
>   
> system.time(s1 <- ifelse(C == "a", 1, -1))
   user  system elapsed
   0.04    0.01    0.08
> system.time(s2 <- 2 * (C == "a") - 1)
   user  system elapsed
      0       0       0


I am just wondering: how comes the time does add up to 0.05 while
elapsed states 0.08 on my system? (Vista+R2.5.1)

Stefan


-=-=-
... Time is an illusion, lunchtime doubly so. (Ford Prefect)



More information about the R-help mailing list