- 此问题在此处已有答案**:
Convert the values in a column into row names in an existing data frame(5个答案)
3天前关闭。
我想将第一列指定为行名称kirp.mut
。
rownames(kirp.mut) <- kirp.mut[,1]
kirp.mut[,1] <- NULL
追溯:
> rownames(kirp.mut) <- kirp.mut[,1]
Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length
In addition: Warning message:
Setting row names on a tibble is deprecated.
尺寸:
> dim(kirp.mut)
[1] 283 8654
类别:
> class(kirp.mut)
[1] "tbl_df" "tbl" "data.frame"
typeof(kirp.mut)
[1] "list"
数据:
> dput(kirp.mut[1:10,1:10])
structure(list(sample_id = c("TCGA-2Z-A9J1-01A-11D-A382-10",
"TCGA-B9-A5W9-01A-11D-A28G-10", "TCGA-GL-A59R-01A-11D-A26P-10",
"TCGA-2Z-A9JM-01A-12D-A42J-10", "TCGA-A4-A57E-01A-11D-A26P-10",
"TCGA-BQ-7044-01A-11D-1961-08", "TCGA-HE-7130-01A-11D-1961-08",
"TCGA-UZ-A9Q0-01A-12D-A42J-10", "TCGA-HE-A5NI-01A-11D-A26P-10",
"TCGA-WN-A9G9-01A-12D-A36X-10"), NBPF1 = c(1, 0, 0, 0, 0, 0,
0, 0, 0, 0), CROCC = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), SF3A3 = c(1,
0, 0, 0, 0, 0, 0, 0, 0, 0), GUCA2A = c(1, 0, 0, 0, 0, 0, 0, 0,
0, 0), RAVER2 = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), ACADM = c(1,
0, 0, 0, 0, 0, 0, 0, 0, 0), PDE4DIP = c(1, 0, 0, 0, 0, 0, 0,
0, 0, 0), NUP210L = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), NCF2 = c(1,
0, 0, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
2条答案
按热度按时间rqqzpn5f1#
tibble不能指定行名称。您可以将其转换为其他格式,如数据框,然后指定行名称。您也可以在tibble上使用
column_to_rownames
执行此tidyverse
解决方案,而无需显式转换为其他格式,但它将在内部执行此操作并返回data.frame
:有关行名称和tibble,请参见技术文档here
zbsbpyhn2#
转换为矩阵(不包括第1列),然后指定行名称:
或到 * Dataframe *