Re: [R] yet another vectorization question

2006-01-31 Thread Adrian DUSA
On Tuesday 31 January 2006 06:55, Gabor Grothendieck wrote: On 1/30/06, Patricia J. Hawkins [EMAIL PROTECTED] wrote: [...snip...] #which generalizes to: bb - matrix(1:50, ncol=10, nrow=5, byrow=TRUE) bv - as.vector(bb) ai - as.vector(aa) + rep((1:nrow(aa)-1)*10, each=3) bv[ai] -

[R] yet another vectorization question

2006-01-30 Thread Adrian DUSA
Dear R-helpers, I'm trying to develop a function which specifies all possible expressions that can be formed using a certain number of variables. For example, with three variables A, B and C we can have - presence/absence of A; B and C - presence/absence of combinations of two of them -

Re: [R] yet another vectorization question

2006-01-30 Thread Adrian DUSA
Adrian DUSA adi at roda.ro writes: I'm trying to develop a function [...snip...] Sorry for the traffic, I forgot to say that I'm using library(combinat) for the combn function... Thank you, Adrian __ R-help@stat.math.ethz.ch mailing list

Re: [R] yet another vectorization question

2006-01-30 Thread Jacques VESLOT
this looks similar: do.call(expand.grid,split(t(replicate(3,c(0,1,NA))),1:3)) Adrian DUSA a écrit : Dear R-helpers, I'm trying to develop a function which specifies all possible expressions that can be formed using a certain number of variables. For example, with three variables A, B and C

Re: [R] yet another vectorization question

2006-01-30 Thread Philippe Grosjean
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)) Best, Philippe Grosjean Jacques VESLOT wrote: this looks similar: do.call(expand.grid,split(t(replicate(3,c(0,1,NA))),1:3)) Adrian DUSA a

Re: [R] yet another vectorization question

2006-01-30 Thread Adrian Dusa
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)) Best, Philippe Grosjean Jacques VESLOT wrote: this looks similar:

Re: [R] yet another vectorization question

2006-01-30 Thread Adrian Dusa
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,

Re: [R] yet another vectorization question

2006-01-30 Thread Patrick Burns
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 [EMAIL PROTECTED] +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

Re: [R] yet another vectorization question

2006-01-30 Thread Adrian Dusa
On Monday 30 January 2006 21:44, Patrick Burns wrote: 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) Indeed! Excellent, thanks :) Hmm, I was just thinking perhaps my first example was too cluttered to

Re: [R] yet another vectorization question

2006-01-30 Thread Patricia J. Hawkins
AD == Adrian Dusa [EMAIL PROTECTED] writes: AD set.seed(5) AD aa - matrix(sample(10, 15, replace=T), ncol=5) AD bb - matrix(NA, ncol=10, nrow=5) AD for (i in 1:ncol(aa)) bb[i, aa[, i]] - c(0, 1, 0) AD Is there any possibility to vectorize this for loop? AD (sometimes I have hundreds of columns

Re: [R] yet another vectorization question

2006-01-30 Thread Gabor Grothendieck
On 1/30/06, Patricia J. Hawkins [EMAIL PROTECTED] wrote: AD == Adrian Dusa [EMAIL PROTECTED] writes: AD set.seed(5) AD aa - matrix(sample(10, 15, replace=T), ncol=5) AD bb - matrix(NA, ncol=10, nrow=5) AD for (i in 1:ncol(aa)) bb[i, aa[, i]] - c(0, 1, 0) AD Is there any possibility to