我有数据框
names <- c("doe.jane", "doe.john", "smith.bob")
number <- c(3, 5, 1)
site <- c("A1", "A1", "A2")
df <- as.data.frame(matrix(c(site, names, number), 3))
names(df) <- c("site", "names", "number")
我只需要用姓氏替换全名,然后折叠数据框,因此输出为
names <- c("doe", "smith")
number <- c(8, 1)
site <- c("A1", "A2")
df <- as.data.frame(matrix(c(site, names, number), 2))
names(df) <- c("site", "names", "number")