Skip to content
Back to formatted view

Raw Message

Message-ID: <1293556489668-3166203.post@n4.nabble.com>
Date: 2010-12-28T17:14:49Z
From: M.Ribeiro
Subject: Faster way to do it??...using apply?
In-Reply-To: <AANLkTi=k=OzMw4aj2d7BA2YkJGCcOv1+ET_gS6+pnuxU@mail.gmail.com>

Hi Henrique,
Thanks for the fast answer,
The only problem in your code, which I think I didn't mention in my message
is that I would like one different random sampling procedure for each 1 in
my vector

The way it was written, it samples only once and replace by every 1:
> x = as.matrix(c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))
> replace(replace(x, x == 1, sample(0:1, 1)), x == 2, 1)
      [,1]
 [1,]    1
 [2,]    1
 [3,]    1
 [4,]    1
 [5,]    1
 [6,]    1
 [7,]    1
 [8,]    1
 [9,]    1
[10,]    1
[11,]    1
[12,]    1
[13,]    1
[14,]    1
[15,]    1

Thanks

-- 
View this message in context: http://r.789695.n4.nabble.com/Faster-way-to-do-it-using-apply-tp3166161p3166203.html
Sent from the R help mailing list archive at Nabble.com.