我在我的data.frame列中存储字符串列表,我希望得到这些列表的长度。
> class(df['4', "generated"])
[1] "list"
> summary(df['4', "generated"])
Length Class Mode
4 180 -none- character
> length(df['4', "generated"])
[1] 1
如上所示 df [" 4","生成"] 属于" list" class,但不是 length的预期结果(df [' 4',"生成"])为180,它显示为1.
请问如何获得真正的列表长度?
UPD: 我从JSON创建数据框,如下所示:
data <- fromJSON("out.json")
matrix <- cbind(id=names(data), t(rbind(sapply(data, "c"))))
df <- data.frame(matrix)
和数据看起来像这样:
{ "4":
{ "generated:
["00A1CD093DB15425310C2BB57CB88BA460C87E5B26BAB3867D26870914E80603",
"018BE455F4A178A33517E3586AF115C9DF7356895B9A7416AD8D20D660B0866D",
"04C5893516CE5C3A6ADC907EC1484DE7542189E9AC7F138EE57DF088EF2F9D92",
<cut>]
}
}
答案 0 :(得分:0)
尝试:
length(df['4', "generated"][[1]])
如果这适用于&#34;生成的每个列表&#34;柱:
sapply(sapply(df[,"generated",drop=F],"[[",1),length)