Ceri
Ceri

Reputation: 27

R: Extracting the length of characters within a large list

Large list

Is there a possibility to create a variable that captures the length of each chr string within a large list in R?

For example in from the picture above I would like to create a variable that captures that the first chr has a length of 0 the second one a length of 3, the third one a length of 4 and so on.

Thanks!

Upvotes: 1

Views: 888

Answers (2)

Punintended
Punintended

Reputation: 737

The lengths command is a built-in that doesn't require applying!

lengths(list(c("test", "one"),
         c("testingtwo"),
         c("this", "is", "test", "three")
        ))

[1] 2 1 4

Upvotes: 4

divibisan
divibisan

Reputation: 12155

sapply(hunspell, length)

This will apply the length function to each element of hunspell and return the result as a vector. Is that what you want?

Upvotes: 0

Related Questions