filter_by_tweet_type: Filter a Twitter dataset to only include statuses of a...

View source: R/analyze-network.R

filter_by_tweet_typeR Documentation

Filter a Twitter dataset to only include statuses of a particular type

Description

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().

Usage

filter_by_tweet_type(df, type)

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 typeinclude "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



example_url <- "18clYlQeJOc6W5QRuSlJ6_v3snqKJImFhU42bRkM_OX8"
tags_content <- read_tags(example_url)

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")
}



bretsw/rtags documentation built on Feb. 4, 2024, 6:20 a.m.