我有一个这样的数据框:
df VALUE ABS_CALL DETECTION P-VALUE 1007_s_at "957.729231881542" "P" "0.00486279317241156" 1053_at "320.632701283368" "P" "0.0313356324173416" 117_at "429.842323161046" "P" "0.0170004527476119" 121_at "2395.7364289242" "P" "0.0114473584876183" 1255_g_at "116.493632746934" "A" "0.39799368200131" 1294_at "739.927122116896" "A" "0.0668649772942343"
我想将行名转换为第一列。目前我使用这样的东西将行名作为第一列:
d <- df names <- rownames(d) rownames(d) <- NULL data <- cbind(names,d)
有没有一条线可以做到这一点?
或者您可以使用tibble‘srownames_to_column与大卫的回答相同:
tibble
rownames_to_column
library(tibble) df <- tibble::rownames_to_column(df, "VALUE")
注意:之前调用的函数add_rownames()已被弃用,正在被替换为tibble::rownames_to_column()
add_rownames()
tibble::rownames_to_column()