I created this table:
> 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
and I put the command
row <- strsplit(rownames(table), "_[0-9]+")
to eliminate the underscore and the number of the elements after the name. I would to create a new table like this example:
> 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
I've tried this command:
> 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’
How can I solve it?
Your issue is that you are trying to assign duplicate row.names, which is not legal - multiple rows would be named Simple_repeat
. One solution is to make the names unique, for example with:
row.names(table) <- make.unique(row)
Another solution is to not make use of row names at all, but create a separate column and then use that for further processing instead of row names, e.g.
table$rowLabel <- row