Count Number of Words in Character String in R (Example) | How to Apply lengths & gregexpr Functions

preview_player
Показать описание
How to count the number of words in a character string in the R programming language. More details:

x <- "This is my +++ character § string + - Hello" # Example string

lengths(gregexpr("\\W+", x)) + 1 # Apply gregexpr & lengths

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

Quite useful! But if I want to count numbers of words of thousands of texts, what should I do then? I hope I don't have to run the line you offered for each text, i.e., to run the line thousands of times...

adlerzhou
Автор

can you explain what the "\\W+" is ?

콘충이
visit shbcf.ru