[英]For every unit increase in one column value , another column entries increase
I have a simulation dataset with 500 replicates - each replicate contains 300 ids.我有一个包含 500 个副本的模拟数据集 - 每个副本包含 300 个 ID。 When rep = 1, id ranges from 1-300;
当 rep = 1 时,id 范围为 1-300; when rep = 2, id again ranges from 1-300 and so on.
当 rep = 2 时,id 再次在 1-300 之间,依此类推。
I want to get the following: when rep = 1: id 1-300;我想得到以下信息:当 rep = 1: id 1-300; when rep = 2: id 301-600 and so on.
当 rep = 2 时:id 301-600 等等。 This can be easily done using an if-else statement if number of replicates is relatively small - like the following code does the job for four replicates:
如果复制的数量相对较少,这可以使用 if-else 语句轻松完成 - 就像下面的代码完成四次复制的工作:
d1 <- mutate(d1, ID = ifelse(rep==1, id,
ifelse(rep==2, id+300,
ifelse(rep==3, id+600, id+900))))
But how should I address this when I have 500 replicates?但是当我有 500 个重复时,我应该如何解决这个问题? So essentially my question is: how should I code - for every unit increase in replicate column, the id column will increase by 300?
所以基本上我的问题是:我应该如何编码 - 对于复制列中的每个单位增加,id 列将增加 300? I have attached the result for 4 replicates (the result of the above code).
我附上了 4 次重复的结果(上述代码的结果)。
Here is a snapshot of the data: replicate 1 replicate 4这是数据的快照:复制 1复制 4
I would use rep
to identify the id
, like:我会使用
rep
来识别id
,例如:
d1 <- mutate(d1, ID = id + 300*(rep-1))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.