Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Find length of each factor in a column in a data frame [duplicate]

$
0
0

This question already has an answer here:

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.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>