Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想向数据框的第一列和第一行添加一个新值。
数据样本:
ali ata 1 u w 2 y e 3 t r 4 f x 5 s z
预期成绩:
ali ata 1 ttt NA 2 u w 3 y e 4 t r 5 f x 6 s z
读取数据。在这里,将字符串编码为字符串(而不是因子)很重要:
df <- read.table(text="ali ata 1 u w 2 y e 3 t r 4 f x 5 s z", header = TRUE, stringsAsFactors = FALSE)
您可以使用rbind添加值:
rbind
rbind(c("ttt", rep(NA, ncol(df) - 1)), df) ali ata 1 ttt <NA> 11 u w 2 y e 3 t r 4 f x 5 s z