
Filter a Twitter dataset to only include statuses of a particular type
Source:R/analyze-network.R
filter_by_tweet_type.Rd
Starting with a dataframe of Twitter data imported to R with
read_tags()
and additional metadata retrieved by
pull_tweet_data()
, filter_by_tweet_type()
processes the
statuses by calling process_tweets()
and then removes any statuses
that are not of the requested type (e.g., replies, retweets, and quote
tweets). filter_by_tweet_type()
is a useful function in itself, but it is
also used in create_edgelist()
.
Arguments
- df
A dataframe returned by
pull_tweet_data()
- type
The specific kind of statuses that will be kept in the dataset after filtering the rest. Choices for
type
include "reply", "retweet", "quote", and "original".
Value
A dataframe of processed statuses and fewer rows that the input dataframe. Only the statuses of the specified type will remain.
Examples
# \donttest{
example_url <- "18clYlQeJOc6W5QRuSlJ6_v3snqKJImFhU42bRkM_OX8"
tags_content <- read_tags(example_url)
#> ✔ Reading from "#aect19 tweet collector".
#> ✔ Range ''Archive''.
if (rtweet::auth_has_default()) {
tweets_data <- lookup_many_tweets(tags_content)
only_replies <- filter_by_tweet_type(tweets_data, "reply")
only_retweets <- filter_by_tweet_type(tweets_data, "retweet")
only_quote_tweets <- filter_by_tweet_type(tweets_data, "quote")
only_originals <- filter_by_tweet_type(tweets_data, "original")
}
# }