将R数据帧中的第一列转换为行名时出错



我有下面这样的数据集,

exp.data <- structure(list(Fasta.headers = c(">O76070ups|SYUG_HUMAN_UPS Gamma-synuclein (Chain 1-127) - Homo sapiens (Human)", 
">Q06830ups|PRDX1_HUMAN_UPS Peroxiredoxin 1 (Chain 2-199) - Homo sapiens (Human)", 
">P06396ups|GELS_HUMAN_UPS Gelsolin (Chain 28-782) - Homo sapiens (Human);>Q3SX14 TREMBL:Q3SX14 (Bos taurus) Similar to Gelsolin", 
">P02768-1 SWISS-PROT:P02768-1 Tax_Id=9606 Gene_Symbol=ALB Isoform 1 of Serum albumin precursor;>P02768ups|ALBU_HUMAN_UPS Serum albumin (Chain 26-609) - Homo sapiens (Human)", 
">P02741ups|CRP_HUMAN_UPS C-reactive protein (Chain 19-224) - Homo sapiens (Human)", 
">P16083ups|NQO2_HUMAN_UPS Ribosyldihydronicotinamide dehydrogenase [quinone] (Chain 2-231) - Homo sapiens (Human)", 
">P05413ups|FABPH_HUMAN_UPS Fatty acid-binding protein, heart (Chain 2-133) - Homo sapiens (Human)", 
">P10636-8ups|TAU_HUMAN_UPS Microtubule-associated protein tau {Isoform Tau-F (Tau-4)} (Chain 2-441) - Homo sapiens (Human)", 
">P02788ups|TRFL_HUMAN_UPS Lactotransferrin (Chain 20-710) - Homo sapiens (Human)", 
">P06732ups|KCRM_HUMAN_UPS Creatine kinase M-type (Chain 1-381) - Homo sapiens (Human)"
), A1 = c(28.8484762528371, 28.5593417132562, 29.8009889375404, 
30.236308349045, 26.8634920403497, 29.2127142763584, 27.8652758954981, 
29.6272988793104, 30.3481913968282, 29.2592834274184), A2 = c(28.6976154934535, 
28.5259670144823, 29.7664700243508, 30.1817239029611, 26.8135256143612, 
29.0836758932669, 27.7993403923308, 29.5523797986127, 30.2273068960395, 
29.1884400603861), A3 = c(28.6907247615967, 28.4075268367718, 
29.945806961862, 30.1906689352863, 26.8775178221577, 29.1529637057232, 
27.848922423631, 29.5442401945692, 30.178874360984, 29.1770925073523
), B1 = c(21.4759289585346, 21.8116726154379, 21.0287288705184, 
21.6755517309807, 22.3711955096869, 20.5319556862522, 20.7294049265441, 
21.2970281676679, 20.0495639422741, 19.6827358066659), B2 = c(21.2438429926591, 
21.5540102900844, 21.1130287737854, 21.2063689577213, 22.5489466679164, 
20.622315219241, 20.8206334182144, 20.5006547822998, 20.1378005068828, 
19.7693579893069), B3 = c(21.9123487685507, 22.2790808524578, 
21.1321045998028, 22.3747058136723, 22.3639090145369, 20.6142641267144, 
20.8125049009101, 22.3532438314135, 20.1299385722048, 19.7616398971008
)), row.names = c(NA, 10L), class = "data.frame")

我想将第一列转换为数据帧的行名。我试过很多代码,比如

cts <- exp.data
cts2 <- cts[,-1]
exp.data <- cbind (cts2, cts)
rownames(cts2) <- cts[,1]
rownames(exp.data) <- exp.data$Fasta.headers

以及其他一些方式。但一直以来,我都会遇到同样的错误,

Error in `.rowNamesDF<-`(x, value = value) : 
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘>O00762ups|UBE2C_HUMAN_UPS Ubiquitin-conjugating enzyme E2 C (Chain 1-179, N-terminal His tag)- Homo sapiens (Human)’, ‘>O76070ups|SYUG_HUMAN_UPS Gamma-synuclein (Chain 1-127) - Homo sapiens (Human)’, ‘>P00167ups|CYB5_HUMAN_UPS Cytochrome b5 (Chain 1-134, N-terminal His tag) - Homo sapiens (Human)’, ‘>P00441ups|SODC_HUMAN_UPS Superoxide dismutase [Cu-Zn] (Chain 2-154) - Homo sapiens (Human)’, ‘>P00709ups|LALBA_HUMAN_UPS Alpha-lactalbumin (Chain 20-142) - Homo sapiens (Human)’, ‘>P00915ups|CAH1_HUMAN_UPS Carbonic anhydrase 1 (Chain 2-261) - Homo sapiens (Human)’, ‘>P00918ups|CAH2_HUMAN_UPS Carbonic anhydrase 2 (Chain 2-260) - Homo sapiens (Human)’, ‘>P01008ups|ANT3_HUMAN_UPS Antithrombin-III (Chain 33-464) - Homo sapiens (Human)’, ‘>P01031ups|CO5_HUMAN_UPS Complement C5 (C5a anaphylatoxin) (Chain 678-751) - Homo sapiens (Human)’, ‘>P01112ups|RASH_HUMAN_UPS GTPase HRas (Chain 1-189) - Homo sapiens (Human) [... truncated] 

因此,请为这个问题提供一些解决方案。

最后,我得到了答案。

exp.data <- exp.data1[,-1]
rownames(exp.data) <- make.names(exp.data1$Fasta.headers, unique = TRUE)
library(dplyr)    
exp.data %>% tibble::column_to_rownames(var = "Fasta.headers")

最新更新