How to count the occurrence of a word in a textual corpus of R?

Asked

Viewed 30 times

1

I’m running a lexical analysis with a pretty large database. Since there are many terms, R says that there is no vector memory to form the matrix with each of the terms and their respective frequency.

Since I can’t export frequencies of all terms, I’d like to identify the frequency of just a few words in the corpus. How can I do that? I tried that way and it didn’t work:

casos = tm_map(corpus, grep, pattern = "||<termo"
sum(unlist(casos))

The error that appears is as follows:

'invalid type (Character) of argument.

Thank you!

  • Welcome to Sopt. Try using reprex to reproduce your problem. Without a reproducible example it is difficult to help you

  • 1

    The code you put above has a problem. "It seems" (not knowing what you want to do) that a close function call ), after "||termo". And that sum... would be another line.

  • What class of unlist(casos) and of cases? It seems to be the case that you are applying an operation on a Character that cannot be performed with this type of data. Probably in the sum or in the unlist is that mistake

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.