我在 R 中有這個資料框
mat <-structure(list(a = c(2, 5, 90, 77, 56), b = c(45, 78, 98, 55,
63), c = c(77, 85, 3, 22, 4), d = c(52, 68, 4, 25, 79), e = c(14,
73, 91, 87, 94)), class = "data.frame", row.names = c(NA, -5L
))
我想添加一行“0”作為墊子的第一行。我需要的輸出是
a b c d e
1 0 0 0 0 0
2 2 45 77 52 14
3 5 78 85 68 73
4 90 98 3 4 91
5 77 55 22 25 87
6 56 63 4 79 94
我能怎么做?謝謝
uj5u.com熱心網友回復:
我們可以用rbind
mat <- rbind(0, mat)
-輸出
mat
a b c d e
1 0 0 0 0 0
2 2 45 77 52 14
3 5 78 85 68 73
4 90 98 3 4 91
5 77 55 22 25 87
6 56 63 4 79 94
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/474483.html
