我使用tidyr
(0.4.0版)中的nest
函数在一个简单的数据帧中嵌套变量:
df <- structure(list(id = 1:4, type = c("B", "A", "B", "B")),
class = "data.frame", row.names = c(NA, -4L),
.Names = c("id", "type"))
df
# id type
# 1 1 B
# 2 2 A
# 3 3 B
# 4 4 B
tidyr::nest(df, id)
# type data
# 1 B 2
# 2 A 1, 3, 4
为什么嵌套数据帧的第一行没有type = "A", data = 2
?这是一个bug吗?或者我只是误解了nest
应该做什么?
发布于 2016-01-21 21:10:03
tidyr 0.3.1
为我生成了正确的输出:
library(tidyr)
df <- structure(list(id = 1:4, type = c("B", "A", "B", "B")),
class = "data.frame", row.names = c(NA, -4L),
.Names = c("id", "type"))
df2 <- nest(df, id)
as.data.frame(df2)
# type id
# 1 A 2
# 2 B 1, 3, 4
sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
https://stackoverflow.com/questions/34934047
复制相似问题