1

I have this:

library(tidytext)
list_chars <- list("you and I", "he or she", "we and they")
list_chars_as_tibble <- lapply(list_chars, tibble)
list_chars_by_word <- lapply(list_chars_as_tibble, unnest_tokens)

got this:

Error in check_input(x) : 
  Input must be a character vector of any length or a list of character
  vectors, each of which has a length of 1.

want to get this:

[[1]]
1 you
2 and
3 I

[[2]]
1 he
2 or
3 she

[[3]]
1 we
2 and
3 they

please help, I believe I have tried everything, but evidently no, thanks

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
nasifffors
  • 25
  • 5

1 Answers1

0

unnest_tokens() needs to be told which column to parse, so you need to name the character column in your tibbles:

library(tidytext)
library(tibble)

list_chars_as_tibble <- lapply(list_chars, function(x) tibble(txt = x))
lapply(list_chars_as_tibble, unnest_tokens, word, txt)

[[1]]
# A tibble: 3 x 1
  word 
  <chr>
1 you  
2 and  
3 i    

[[2]]
# A tibble: 3 x 1
  word 
  <chr>
1 he   
2 or   
3 she  

[[3]]
# A tibble: 3 x 1
  word 
  <chr>
1 we   
2 and  
3 they 
Ritchie Sacramento
  • 29,890
  • 4
  • 48
  • 56
  • thanks H 1, it works like a charm, where can I learn things like that? Where can I close this question? – nasifffors Apr 12 '20 at 12:15
  • Thanks... I don't see the "tick" where to close this post... all I have are three squares next to the answer with "active", "oldest", "votes", I click votes but nothing – nasifffors Apr 12 '20 at 12:37