This question already has an answer here:
- Using nchar function on factor variables 3 answers
I have a data frame with which is the wordcount of each word in a text file, so
> head(wordcount)
word freq
1 MARCHER 23
2 JAILLE 23
10 OKI 28
11 MUSICIENS 18
14 UNIQUEMENT 20
15 PRODUCTIF 20
Each of the words is stored as a factor in the df. I need them to stay as factors for a future function.
How can I find the length of each word in my df? I'd like to filter out words of a certain length, but I'm stumped as to how to go about it.
I've tried wordcount$wordlength = sapply(wordcount$word, nchar)
, but that requires a character vector not factors, and wordcount$wordlength = sapply(wordcount$word, length)
, but that just returned a vecotr full of ones.