[R] yet another vectorization question

Patrick Burns pburns at pburns.seanet.com
Mon Jan 30 20:44:35 CET 2006


I tried to let this pass, but failed:

lapply(1:3, function(x) c(0, 1, NA))

might more clearly be written as

rep(list(c(0, 1, NA)), 3)



Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

Adrian Dusa wrote:

>On Monday 30 January 2006 14:40, Philippe Grosjean wrote:
>  
>
>>Hello,
>>Not exactly the same. By the way, why do you use do.call()? Couldn't you
>>do simply:
>>expand.grid(split(t(replicate(3, c(0, 1, NA))), 1:3))
>>    
>>
>
>Just for the sake of it, the above can be even more simple with:
>
>expand.grid(lapply(1:3, function(x) c(0, 1, NA)))
>
>Best,
>Adrian
>
>  
>




More information about the R-help mailing list