search for: swapm

Displaying 4 results from an estimated 4 matches for "swapm".

Did you mean: swap
2017 Jul 06
3
Efficient swapping
...tmp[ii,]$R1 <- tmp[ii,]$R2 tmp[ii,]$R2 <- qq } } How to go about this case? Thanks! On Thu, Jul 6, 2017 at 5:16 PM, Ista Zahn <istazahn at gmail.com> wrote: > How about > > foo <- with(list(r1 = tmp$R1, > r2 = tmp$R2, > swapme = (as.numeric(tmp$R1) - as.numeric(tmp$R2)) %% 2 != 0), > { > tmp[swapme, "R1"] <- r2[swapme] > tmp[swapme, "R2"] <- r1[swapme] > tmp > }) > > Best, > Ista > > On Thu, Jul 6, 2017 at 4:06 PM, Gang Chen <gangchen6 at gmail.com&g...
2017 Jul 06
0
Efficient swapping
How about foo <- with(list(r1 = tmp$R1, r2 = tmp$R2, swapme = (as.numeric(tmp$R1) - as.numeric(tmp$R2)) %% 2 != 0), { tmp[swapme, "R1"] <- r2[swapme] tmp[swapme, "R2"] <- r1[swapme] tmp }) Best, Ista On Thu, Jul 6, 2017 at 4:06 PM, Gang Chen <gangchen6 at gmail.com> wrote: > Suppose that we have the followin...
2017 Jul 06
2
Efficient swapping
Suppose that we have the following dataframe: set.seed(1) (tmp <- data.frame(x = 1:10, R1 = sample(LETTERS[1:5], 10, replace = TRUE), R2 = sample(LETTERS[1:5], 10, replace = TRUE))) x R1 R2 1 1 B B 2 2 B A 3 3 C D 4 4 E B 5 5 B D 6 6 E C 7 7 E D 8 8 D E 9 9 D B 10 10 A D I want to do the following: if the difference between the level index of factor
2017 Jul 06
0
Efficient swapping
...tmp[ii,]$R1 <- tmp[ii,]$R2 tmp[ii,]$R2 <- qq } } How to go about this case? Thanks! On Thu, Jul 6, 2017 at 5:16 PM, Ista Zahn <istazahn at gmail.com> wrote: > How about > > foo <- with(list(r1 = tmp$R1, > r2 = tmp$R2, > swapme = (as.numeric(tmp$R1) - as.numeric(tmp$R2)) %% 2 != 0), > { > tmp[swapme, "R1"] <- r2[swapme] > tmp[swapme, "R2"] <- r1[swapme] > tmp > }) > > Best, > Ista > > On Thu, Jul 6, 2017 at 4:06 PM, Gang Chen <gangchen6 at gmail.com&g...