Hi,
I am new with r studio, I will appriciate every help;-).
I have tabel in r studio with different columns. I need to count the words of the column "reviews" and put this output in a new column. How should I do this?
Hi,
I am new with r studio, I will appriciate every help;-).
I have tabel in r studio with different columns. I need to count the words of the column "reviews" and put this output in a new column. How should I do this?
Here's one method using the dplyr
and stringr
packages.
library(dplyr, warn.conflicts = FALSE)
library(stringr)
data <- tibble(reviews = c("the dog is on the mat",
"the cat is on top of the wall"))
data <- mutate(data, word_count = lengths(str_split(reviews, boundary("word"))))
print(data)
#> # A tibble: 2 x 2
#> reviews word_count
#> <chr> <int>
#> 1 the dog is on the mat 6
#> 2 the cat is on top of the wall 8
Created on 2020-05-07 by the reprex package (v0.3.0)
thank you for your time !!!!
No problem. If your issue has been solved, please consider marking my post as a solution.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.