简体   繁体   中英

How to randomly select 2 cells from a horizontal range in Google Sheet or R

I need to pick randomly 2 cells from a row (specific range/columns of the row).

Al  Em  Kev
1   1   2
3   2   3
2   2   1
3   3   3

output:

rand 1  rand 2
2         1
3         2
2         2
3         3

The results need to be unique: the same cell cannot be returned both times.

It would be quicker to do it in Google sheets right now, but an answer using R would be fine as well.

Thanks guys

我们可以通过apply做到这一点

t(apply(data, 1, function(x) sample(x, 2))) 
=SPLIT(INDIRECT(CHAR(RANDBETWEEN(65,67))&ROW())&
   "♥"&INDIRECT(CHAR(RANDBETWEEN(65,67))&ROW()),"♥")

0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM