Sunteți pe pagina 1din 8

General R commands

getwd()
typeof(objeoctname)
ncol(a dataframe) // nrow(a dataframe) // colnames(a dataframe)
dataframe[,c("column1", "column2",)]
dataframe[dataframe$columnName>=x,c("column1", "column2",)]
dataframe[order(dataframe$column),]
rbind(dataframe1, dataframe2)
write.csv(currentdataframe, file="newCSV.csv")

Twitter Commands
setup_twitter_oauth(
twListToDF(userTimeline("username", n= , includeRts = FALSE/TRUE, excludeReplies = FALSE/TRUE))
twListToDF(searchTwitter("#hashtag+#...", lang = "en/es/", n =, since = "year-month-day", until = "year, month, day", geocode
getUser("user")
user$created or user$favorites.
as.data.frame(value)
lookupUsers(c("user", "user2", "user3"))
availableTrendLocations()
getTrends(woeid="#####")
userTimeline("user", n=, maxID=NULL, sinceID=NULL, includeRts=FALSE, excludeReplies=FALSE)

Facebook Commands
fbOAuth('','', extended_permissions=TRUE, legacy_permissions=FALSE)
searchPages("search", token, n=)
getPage("pageIDnameor#", token, n=, since=, until=, reactions = TRUE)
getPost("postID_PageID", token, n=)
FBPost_Dataframe$comments or FBPost_Dataframe$likes
searchGroup("search", token)
getGroup(group_id="ID#", token, n=)
dataframe[is.na(dataframe)] <- 0
dataframe$NewColumnofMath <- apply(dataframe[,c("column1", "column3")], 1, sum/mean/etc)

TimeStamp Commands
ymd_hms(dataframe$created)
with_tz(dataframe$created, "America/New_York")

Cleaning Commands
str_replace_all(dataframe$text, "@\\w+", "")
Sentiment Commands
get_nrc_sentiment(dataframe$clean_text)
cbind(dataframe, sentimentsframe)

Putting Sentiments into Plots


dailysentiment <- COMBINEDDATA_SENTIMENT %>% group_by(created_date) %>% summarise(anger=mean(anger), anticipatio
names(dailysentiment) <- c("day", "sentiment", "meanvalue")
dailysentiment$day <- as.Date(dailysentiment$day)

ggplot(data = dailysentiment, aes(x=day, y = meanvalue, group = sentiment)) + geom_line(size=1.5, alpha = 0.7, aes(color=senti

h1 <- hPlot(x = "day_show", y = "meanvalue", data = dailysentiment, type = "line", group = "sentiment")
h1$print("chart5",include_assets = TRUE)
h1
working directory
defines the object
number of columns // number of rows // names of columns
saves new dataframe of listed columns
munges the data to given parameters (more than, less than, equal to) in given columns (don't know how to do multiple column
orders the given column
binds dataframes together
writes to csv file

sets up twitter authentication: need tokens setup_twitter_oauth('u3c5xOLH5ui3gYqBlAwXjtxpb', 'LyvHf4qUgLKuAQfMGWlD


acquire tweets into dataframe
search twitter for specific hashtags
gets account info of user
extracts particular details of user
turns a value into a dataframe
gets multiple accounts' info, results as list of lists
gets woeid codes to use for getTrends function
gets the trends of given location
gets user's timeline as a list of values. Not sure how to use it

fb token bro token <- fbOAuth('152490112010756','59fdb6332128028d85a8430cdaf46186', extended_perm


search public facebook pages
get dataframe of posts
get info, n=#of comments specifically I think
extracts comments or likes
searches public groups
mines the open group
sets one up for calculating??
adds new column of calculations

adjusts all timestamps to Year-Month-Day


sets timezone to NYC

removes special objects from text; there are other codes for other effects apparently
produces new dataframe of JUST sentiments
make dataframe of data+sentiments

nticipation), disgust=mean(fear), joy=mean(joy), sadness=mean(sadness),surprise=mean(surprise), trust=mean(trust))%>%melt

om_point(size=.5) + ylim(0,NA) + theme(legend.title=element_blank(), axis.title.x = element_blank()) + ylab("Average Sentiment Score") +


w how to do multiple columns at a time)

, 'LyvHf4qUgLKuAQfMGWlDBYgLxW8Ta1cCNtX92dOJ1Xblkgp7Jj', access_token='869231931380162561-PzIOMF9BJ2wsa5GbuNn2fEd2v11w

0cdaf46186', extended_permissions = TRUE, legacy_permissions = FALSE)


(trust))%>%melt

Average Sentiment Score") + ggtitle("Sentiments Over Time")


IOMF9BJ2wsa5GbuNn2fEd2v11wcRk', access_secret='puFDMKudQDPuEEMtjbIBYsndQeA2gpIsX4xIvqT0MaMGl')
library(ggplot2)
library(lubridate)
library(scales)
library(tm)
library(stringr)
library(wordcloud)
library(syuzhet)
library(reshape2)
library(dplyr)
library(twitteR)
require(devtools)
library(Rfacebook)

S-ar putea să vă placă și