Skip to content

Instantly share code, notes, and snippets.

Last active December 5, 2015 02:16
Show Gist options
  • Save micahwoods/6dc28df64a6e5fc4f95d to your computer and use it in GitHub Desktop.
Save micahwoods/6dc28df64a6e5fc4f95d to your computer and use it in GitHub Desktop.
Counts the number of unique followers of selected turfgrass accounts on Twitter
# this code will download twitter follower information
# load packages
api_key <- "your api key"
api_secret <- "your api secret"
access_token <- "your access token"
access_token_secret <- "your access token secret"
setup_twitter_oauth(api_key, api_secret, access_token, access_token_secret)
# get the account to work with
td <- getUser("GolfSupers")
# download follower info and convert to data frame
td.follower <- lookupUsers(td$getFollowerIDs())
golfsupers <- twListToDF(td.follower)
# write the file to the working directory
write.csv(golfsupers, "golfsupers.csv", row.names = FALSE)
# after downloading the data for all accounts of interest
# and writing to the working directory, one can read the files
GCImagazine <- read.csv("GCImagazine.csv", header = TRUE)
turfdiseases <- read.csv("turfdiseases.csv", header = TRUE)
gcsaa <- read.csv("gcsaa.csv", header = TRUE)
turfnet <- read.csv("turfnet.csv", header = TRUE)
BIGGALtd <- read.csv("BIGGALtd.csv", header = TRUE)
the_iog <- read.csv("the_iog.csv", header = TRUE)
agcsa2 <- read.csv("agcsa2.csv", header = TRUE)
golfsupers <- read.csv("golfsupers.csv", header = TRUE)
# assign the account name variable to each of the data sets
GCImagazine$account <- "GCImagazine"
gcsaa$account <- "gcsaa"
turfdiseases$account <- "TurfDiseases"
turfnet$account <- "TurfNet"
BIGGALtd$account <- "BIGGALtd"
the_iog$account <- "the_iog"
agcsa2$account <- "agcsa2"
golfsupers$account <- "GolfSupers"
# combine the accounts into one data frame
all <-, gcsaa, turfdiseases, turfnet,
BIGGALtd, the_iog, agcsa2, golfsupers)
# count the unique followers
allUnique <- unique(all$id)
# filter out the accounts with no tweets
no <- filter(all, statusesCount > 0)
# count the unique followers for accounts that have sent at least 1 tweet
noUnique <- unique(no$id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment