Tekst als data

Introductie tot tekstanalyse in R

Maham Faisal Khan

Senior Data Science Content Developer, DataCamp

Het tidyverse gebruiken

Introductie tot tekstanalyse in R

Het tidyverse gebruiken

Introductie tot tekstanalyse in R

Het tidyverse gebruiken

Introductie tot tekstanalyse in R

Pakketten laden

library(tidyverse)
-- Pakketten worden geladen ------------------------------- tidyverse 1.2.1 --
v ggplot2 3.0.0     v purrr   0.2.5
v tibble  2.0.0     v dplyr   0.7.8
v tidyr   0.8.2     v stringr 1.3.1
v readr   1.1.1     v forcats 0.3.0
-- Conflicten ------------------------------------- tidyverse_conflicts() --
x dplyr::filter() maskeert stats::filter()
x dplyr::lag()    maskeert stats::lag()
Introductie tot tekstanalyse in R

Reviewdata importeren

review_data <- read_csv("Roomba Reviews.csv")

review_data
# A tibble: 1,833 x 4
   Date     Product               Stars Review
   <chr>    <chr>                 <dbl> <chr>
 1 2/28/15  iRobot Roomba 650 fo…     5 You would not believe how well...
 2 1/12/15  iRobot Roomba 650 fo…     4 You just walk away and it does... 
 3 12/26/13 iRobot Roomba 650 fo…     5 You have to Roomba proof your...
 4 8/4/13   iRobot Roomba 650 fo…     3 Yes, its a fascinating, albeit...
# … met nog 1.829 rijen
Introductie tot tekstanalyse in R

filter() en summarize() gebruiken

review_data %>% 
  filter(product == "iRobot Roomba 650 for Pets") %>% 
  summarize(stars_mean = mean(stars))
# A tibble: 1 x 1
  stars_mean
       <dbl>
1       4.49
Introductie tot tekstanalyse in R

group_by() en summarize() gebruiken

review_data %>% 
  group_by(product) %>% 
  summarize(stars_mean = mean(stars))
# A tibble: 2 x 2
  product                                  stars_mean
  <chr>                                         <dbl>
1 iRobot Roomba 650 for Pets                     4.49
2 iRobot Roomba 880 for Pets and Allergies       4.42
Introductie tot tekstanalyse in R

Ongestructureerde data

review_data %>% 
  group_by(product) %>% 
  summarize(review_mean = mean(review))
Waarschuwingen:
1: In mean.default(review) :
  argument is niet numeriek of logisch: NA teruggegeven
2: In mean.default(review) :
  argument is niet numeriek of logisch: NA teruggegeven
Introductie tot tekstanalyse in R

Laten we oefenen!

Introductie tot tekstanalyse in R

Preparing Video For Download...