[R] complexity of operations in R

Joshua Wiley jwiley.psych at gmail.com
Thu Jul 19 18:23:21 CEST 2012


also rep.int()

> system.time(for (i in 1:1000) x <- rep.int(FALSE, 100000))
   user  system elapsed
   0.29    0.02    0.29
> system.time(for (i in 1:1000) x <- rep(FALSE, 100000))
   user  system elapsed
   1.96    0.08    2.05

On Thu, Jul 19, 2012 at 9:11 AM, Bert Gunter <gunter.berton at gene.com> wrote:
> Hadley et. al:
>
> Indeed. And using a loop is a poor way to do it anyway.
>
> v <- as.list(rep(FALSE,dotot))
>
> is way faster.
>
> -- Bert
>
> On Thu, Jul 19, 2012 at 8:50 AM, Hadley Wickham <hadley at rice.edu> wrote:
>> On Thu, Jul 19, 2012 at 8:02 AM, Jan van der Laan <rhelp at eoos.dds.nl> wrote:
>>> Johan,
>>>
>>> Your 'list' and 'array doubling' code can be written much more efficient.
>>>
>>> The following function is faster than your g and easier to read:
>>>
>>> g2 <- function(dotot) {
>>>   v <- list()
>>>   for (i in seq_len(dotot)) {
>>>     v[[i]] <- FALSE
>>>   }
>>> }
>>
>> Except that you don't need to pre-allocate lists...
>>
>> Hadley
>>
>> --
>> Assistant Professor / Dobelman Family Junior Chair
>> Department of Statistics / Rice University
>> http://had.co.nz/
>>
>> ______________________________________________
>> 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.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>
> ______________________________________________
> 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.



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list