Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何将重复数替换为'-';当它满足其他列的条件时_R_Dataframe_Conditional Statements - Fatal编程技术网

R 如何将重复数替换为'-';当它满足其他列的条件时

R 如何将重复数替换为'-';当它满足其他列的条件时,r,dataframe,conditional-statements,R,Dataframe,Conditional Statements,我有5列(基因型、每个地块的植物、植物编号、H1、H2)。我想用-替换每个图中列plant\u的所有重复编号,条件是:仅保留第一个编号(即与列plant\u编号h1、h2中的行-平行的编号) 它应成为: Genotype Plants_per_plot Plant_no. H1 H2 184 8 - - - 184 - 1 12 50 184 - 2 11 48 184 - 3 11 50 184 - 4 14 52 67 7 - -

我有5列(基因型、每个地块的植物、植物编号、H1、H2)。我想用
-
替换每个图中列plant\u的所有重复编号,条件是:仅保留第一个编号(即与列plant\u编号h1、h2中的行
-
平行的编号)

它应成为:

Genotype Plants_per_plot Plant_no. H1 H2
184 8   -   -   -
184 -   1   12  50
184 -   2   11  48
184 -   3   11  50
184 -   4   14  52
67  7   -   -   -
67  -   1   17  61
67  -   2   20  60
67  -   3   23  59
67  -   4   22  53
98  4   -   -   -
98  -   1   21  52
98  -   2   20  56
98  -   3   18  54
98  -   4   15  52
101 9   -   -   -

我们用
duplicated
创建一个逻辑向量,并将重复项分配给'-`

df1[,2][duplicated(df1[1:2])] <- '-'
df1[,2][重复(df1[1:2])]
df1[,2][duplicated(df1[1:2])] <- '-'