无法更改表的行名

时间:2019-06-03 13:05:59

标签: r rowname

我创建了此表:

> head(table)
                  tissue1 tissue2 tissue3 tissue4 tissue5
Simple_repeat_80   58     77         48     69     115                                   131
tRNA_1              0     14         12      1      19                                     14
Simple_repeat_86    2     10          2      2      14                                       9
Simple_repeat_87    1     33         12      3      15                                      21
Simple_repeat_103   0      0          2      0       0                                       4
SINE/tRNA-Deu_20    0      0          1      0       0                                      10

然后我输入命令 row <- strsplit(rownames(table), "_[0-9]+")消除名称下的下划线和元素数。我将像下面的示例一样创建一个新表:

> head(table)
                  tissue1 tissue2 tissue3 tissue4 tissue5
Simple_repeat   58     77         48     69     115                                   131
tRNA             0     14         12      1      19                                     14
Simple_repeat    2     10          2      2      14                                       9
Simple_repeat    1     33         12      3      15                                      21
Simple_repeat   0      0          2      0       0                                       4
SINE/tRNA-Deu    0      0          1      0       0                                      10

我已经尝试过以下命令:

> row.names(table) = row
Error in `.rowNamesDF<-`(x, value = value) : 
  'row.names' duplicate non sono permesse
Inoltre: Warning message:
non-unique values when setting 'row.names': ‘DNA?’, ‘DNA/hAT-Ac’, ‘DNA/hAT-Charlie’, ‘DNA/hAT-Tag1’, ‘DNA/hAT-Tip100’, ‘DNA/MULE-MuDR’, ‘DNA/PIF-Harbinger’, ‘DNA/PiggyBac’, ‘DNA/TcMar-Mariner’, ‘DNA/TcMar-Tc1’, ‘DNA/TcMar-Tc2’, ‘DNA/TcMar-Tigger’, ‘LINE/CR1’, ‘LINE/Dong-R4’, ‘LINE/I-Jockey’, ‘LINE/L1’, ‘LINE/L2’, ‘LINE/Penelope’, ‘LINE/RTE-BovB’, ‘Low_complexity’, ‘LTR/ERV1’, ‘LTR/ERVK’, ‘LTR/ERVL’, ‘LTR/Gypsy’, ‘LTR/Gypsy?’, ‘RC/Helitron’, ‘rRNA’, ‘Satellite/acro’, ‘Simple_repeat’, ‘SINE/5S-Deu-L2’, ‘SINE/MIR’, ‘SINE/tRNA’, ‘SINE/tRNA-Deu’, ‘SINE/tRNA-RTE’, ‘snRNA’, ‘srpRNA’, ‘tRNA’ 

我该如何解决?

1 个答案:

答案 0 :(得分:2)

您的问题是您试图分配重复的row.name,这是不合法的-多行将被命名为Simple_repeat。一种解决方案是使名称唯一,例如:

row.names(table) <- make.unique(row)

另一种解决方案是根本不使用行名,而是创建一个单独的列,然后使用它代替行名来进行进一步处理,例如

table$rowLabel <- row