我有一个数据框架,如下所示:
> DisintegrationBehavior
gden degree
1.txt 0.45000000 0.7083333
14.txt 0.58333333 0.5000000
11.txt 0.50000000 0.4166667
12.txt 0.50000000 0.6666667
13.txt 0.25000000 0.5000000
我想从行名中删除.txt,然后在每个行号前添加“ team”,然后按行号对结果进行排序(或以较容易的顺序为准),以便最终结果如下所示:
> DisintegrationBehavior
gden degree
team1 0.45000000 0.7083333
team11 0.50000000 0.4166667
team12 0.50000000 0.6666667
team13 0.25000000 0.5000000
team14 0.58333333 0.5000000
谢谢!
你可以做
s <- sub(".txt", "", rownames(df), fixed = TRUE)
rownames(df) <- paste0("team", s)
df[order(as.numeric(s)), ]
# gden degree
# team1 0.4500000 0.7083333
# team11 0.5000000 0.4166667
# team12 0.5000000 0.6666667
# team13 0.2500000 0.5000000
# team14 0.5833333 0.5000000
数据:
df <- structure(list(gden = c(0.45, 0.58333333, 0.5, 0.5, 0.25), degree = c(0.7083333,
0.5, 0.4166667, 0.6666667, 0.5)), .Names = c("gden", "degree"
), class = "data.frame", row.names = c("1.txt", "14.txt", "11.txt",
"12.txt", "13.txt"))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句