1
我试图通过R中的第一列来命名我的行名称,但出现错误invalid 'row.names' length
。添加第一列作为行中的行名称时发生错误
DF
x1 A B
1 a 2 1
2 b 4 2
预期输出
A B
a 2 1
b 4 2
我的代码
df1 <- df[, -1] #remove the first column x1 and create a new df->df1
rownames(df1) <- df[, 1] #add the row names by the first column of df
错误
Error in `row.names<-.data.frame`(`*tmp*`, value = value) : invalid 'row.names' length
谢谢!
我不重现错误。 – agenis
我无法重现此错误。 – CCD
无论如何,你可以尝试'df%>%set_rownames(.x1)%>%select(-x1)'使用magrittr包 – agenis