Evaluating a DTM as a matrix
Let's practice casting our tidy data into a DTM and evaluating the DTM by treating it as a matrix.
In this exercise, you will create a DTM again, but with a much smaller subset of the twitter data (tidy_twitter_subset
).
This exercise is part of the course
Introduction to Text Analysis in R
Exercise instructions
- Cast the word counts by tweet into a DTM and assign it to
dtm_twitter
. - Coerce
dtm_twitter
into a matrix calledmatrix_twitter
. - Print rows 1 through 5 and columns 90 through 95.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Assign the DTM to dtm_twitter
dtm_twitter <- tidy_twitter_subset %>%
count(word, tweet_id) %>%
# Cast the word counts by tweet into a DTM
___(___)
# Coerce dtm_twitter into a matrix called matrix_twitter
___ <- ___(___)
# Print rows 1 through 5 and columns 90 through 95
___