更新时间:2023-10-22 12:03:40
应该这样做:
samp2 <- samp[,-1]
rownames(samp2) <- samp[,1]
简而言之,除了重新分配,别无选择.
So in short, no there is no alternative to reassigning.
纠正自己,也可以原地做:分配rowname属性,然后删除列:
Correcting myself, one can also do it in place: assign rowname attributes, then remove column:
R> df<-data.frame(a=letters[1:10], b=1:10, c=LETTERS[1:10])
R> rownames(df) <- df[,1]
R> df[,1] <- NULL
R> df
b c
a 1 A
b 2 B
c 3 C
d 4 D
e 5 E
f 6 F
g 7 G
h 8 H
i 9 I
j 10 J
R>