diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/twitter-data.Rproj b/twitter-data.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/twitter-data.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/twitter_data.Rmd b/twitter_data.Rmd new file mode 100644 index 0000000..b024b5d --- /dev/null +++ b/twitter_data.Rmd @@ -0,0 +1,59 @@ +--- +title: "twitter" +author: "Jing" +date: "October 11, 2016" +output: pdf_document +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` + +## R Markdown + +This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . + +When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: + +```{r} +twitter_data <- read.csv("HUDK4050-twitter-10-06-16.csv", header=TRUE,sep=",") +View(twitter_data) +``` + +## Including Plots + +You can also embed plots, for example: + +```{r pressure, echo=FALSE} +#plots +plot(twitter_data) #too overwhelming +plot(twitter_data$screenName,twitter_data$time) + +#create subset +D1<-twitter_data$screenName +D2<-twitter_data$time + +#barplot +table<-table(D2,D1) +barplot(table) + +#lineplot +plot(twitter_data$screenName, twitter_data$time, type = "l",lty = "dashed") + #why it is not a line plot, but a boxplot instead??? + +#boxplot +boxplot(twitter_data$time,twitter_data$screenName) + +#use of "aggregate": example of "last day of the month" +dates <- data.frame(date = as.Date("2001-01-01", format = "%Y-%m-%d") + 0:729) +last.day <- aggregate(x = dates["date"], by = list(month = substr(dates$date, 1, 7)), FUN = max) + +#create a table about how many times each person tweet:) or AKA frequency table +library(plyr) +table1<-data.frame(name=twitter_data$screenName,tweet=twitter_data$text) +table2<-count(table1,"name") + +``` + + +Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.