1

This is (part of) the dput() output of a List that I've got.

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"

It either contains a character vector, or character(0).. I want to select only the elements that are written as character(0) but I don't know how. Could anyone help me with this?

Darren
  • 71
  • 6

1 Answers1

2

We can use Filter

Filter(Negate(length), L)

Or another option is sapply

L[!sapply(L, length)]

Or as @MartinMorgan mentioned lengths (introduced in the recent R version) can be used (which would be faster)

L[!lengths(L))
akrun
  • 874,273
  • 37
  • 540
  • 662