简体   繁体   English

如何从 Google Sheet 或 R 的水平范围中随机选择 2 个单元格

[英]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).我需要从一行中随机选择 2 个单元格(该行的特定范围/列)。

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.现在在 Google 表格中这样做会更快,但使用 R 的答案也可以。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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