这是我所拥有的List的dput()输出(的一部分)。
L<-list(c("LumenVox LLC", "LumenVox LLC", "Voxware Inc", "LumenVox LLC",
"Voxware Inc", "Voxant Inc"),character(0), character(0), character(0),
character(0), c("HumanZyme Inc", "ZymeQuest Inc", "Zymetx Inc",
"Zymetx Inc"))
[[1]]
[1] "LumenVox LLC" "LumenVox LLC" "Voxware Inc" "LumenVox LLC" "Voxware Inc" "Voxant Inc"
[[2]]
character(0)
[[3]]
character(0)
[[4]]
character(0)
[[5]]
character(0)
[[6]]
[1] "HumanZyme Inc" "ZymeQuest Inc" "Zymetx Inc" "Zymetx Inc"
它包含一个字符向量或字符(0)..我只想选择写为字符(0)的元素,但我不知道如何。有人可以帮我这个吗?
答案 0 :(得分:2)
我们可以使用Filter
Filter(Negate(length), L)
或另一个选项是sapply
L[!sapply(L, length)]
或者@MartinMorgan提到lengths
(在最近的R版本中引入)可以使用(这会更快)
L[!lengths(L))