4

I'm having some issues with converting a dataframe to use with the tidytext function unnest_tokens

The error is: error in UseMethod("unnest_tokens_") : no applicable method for 'unnest_tokens_' applied to an object of class "character"

From this:

notesWords <- text_df %>% 
        unnest_tokens(word, text) %>%
        count(segment, word, sort = TRUE) %>%
        ungroup()

I'm not sure what the error is telling me, because when I check the type of my input text_df, I get chr [1:6067]

However, because I'm looking at the inputs to a document, I need to input characters, so I'm not sure how to solve this error if it is telling characters should not be inputted. Should I convert the characters to something else?

Thanks,

* UPDATED *

Here is how text_df is created: data.frame(textData['notes'])

The contents of text_df are:

 head(text_df)
                                notes
1                                 foo
2                                 bar
3                                 baz

And str(text_df)

'data.frame': 6067 obs. of 1 variable: $ notes: chr "foo" "bar" "baz" ...

However when I use use the data frame now, the error becomes:

Input must be a character vector of any length or a list of character vectors, each of which has a length of 1.

Chef1075
  • 2,614
  • 9
  • 40
  • 57
  • 1
    Looks like you have a `vector`. Is it a data.frame? Is the column name "text"? The example in `?unnest_tokens` works for me – akrun Jan 15 '18 at 19:26
  • 1
    Yeah, doesn't sound like `text_df` is a data.frame. When asking for help make sure to include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data. This will make it easier to help you. Also include the desired output for the sample input so possible solutions can be tested and verified. – MrFlick Jan 15 '18 at 19:31
  • Updated the question with some sample data – Chef1075 Jan 15 '18 at 21:29
  • My quick guess is that you only have a word in each row of `notes`, so `unnesttokens()` is not working. – jazzurro Jan 15 '18 at 22:53
  • 3
    For your first attempt, you specified a column called `text` for `unnest_tokens()'. But seeing your sample data in your update, you do not have a column called word or text. – jazzurro Jan 15 '18 at 22:56
  • @jazzurro that was the issue. Thank you for seeing that – Chef1075 Jan 16 '18 at 04:48

0 Answers0