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/Class 7 Instructions.Rmd b/Class 7 Instructions.Rmd index 5ae641a..c17d5e4 100644 --- a/Class 7 Instructions.Rmd +++ b/Class 7 Instructions.Rmd @@ -2,6 +2,7 @@ title: "Assignment 3" author: "Charles Lang" date: "February 13, 2016" +output: html_document --- ##In this assignment you will be practising data tidying. You will be using the data we have collected from class and data generated from the instructor wearing a wristband activity tracker. @@ -10,15 +11,15 @@ date: "February 13, 2016" ##Install packages for manipulating data We will use two packages: tidyr and dplyr ```{r} -#Insall packages -install.packages("tidyr", "dplyr") + #Load packages library(tidyr, dplyr) + ``` ##Upload wide format instructor data (instructor_activity_wide.csv) ```{r} -data_wide <- read.table("~/Documents/NYU/EDCT2550/Assignments/Assignment 3/instructor_activity_wide.csv", sep = ",", header = TRUE) +data_wide <- read.table("~/Desktop/FALL_2016/Class7/instructor_activity_wide.csv", sep = ",", header = TRUE) #Now view the data you have uploaded and notice how its structure: each variable is a date and each row is a type of measure. View(data_wide) @@ -59,7 +60,7 @@ instructor_data <- spread(data_long, variables, measure) ##Now we have a workable instructor data set!The next step is to create a workable student data set. Upload the data "student_activity.csv". View your file once you have uploaded it and then draw on a piece of paper the structure that you want before you attempt to code it. Write the code you use in the chunk below. (Hint: you can do it in one step) ```{r} - +Student_data <- spread(data_wide, variable, measure) ``` ##Now that you have workable student data set, subset it to create a data set that only includes data from the second class. @@ -72,10 +73,10 @@ Notice that the way we subset is with a logical rule, in this case date == 20160 student_data_2 <- dplyr::filter(student_data, date == 20160204) ``` -Now subset the student_activity data frame to create a data frame that only includes students who have sat at table 4. Write your code in the following chunk: +Now subset the student_activity data frame to create a data frame that only includes students who have sat at table 4. Write your code in t?he following chunk: ```{r} - +student_data_2 <- dplyr::filter(Student_data, table == 4) ``` ##Make a new variable @@ -89,7 +90,7 @@ instructor_data <- dplyr::mutate(instructor_data, total_sleep = s_deep + s_light Now, refering to the cheat sheet, create a data frame called "instructor_sleep" that contains ONLY the total_sleep variable. Write your code in the following code chunk: ```{r} - +instructor_sleep <- dplyr::select(instructor_data, total_sleep) ``` Now, we can combine several commands together to create a new variable that contains a grouping. The following code creates a weekly grouping variable called "week" in the instructor data set: @@ -100,7 +101,7 @@ instructor_data <- dplyr::mutate(instructor_data, week = dplyr::ntile(date, 3)) Create the same variables for the student data frame, write your code in the code chunk below: ```{r} - +Student_data <- dplyr::mutate(Student_data, week = dplyr::ntile(date, 3)) ``` ##Sumaraizing @@ -117,7 +118,8 @@ student_data %>% dplyr::group_by(date) %>% dplyr::summarise(mean(motivation)) Create two new data sets using this method. One that sumarizes average motivation for students for each week (student_week) and another than sumarizes "m_active_time" for the instructor per week (instructor_week). Write your code in the following chunk: ```{r} - +Student_week %>% dplyr::group_by(week) %>% dplyr::summarise(mean(motivation)) +instructor_week %>% dplyr::group_by(week) %>% dplyr::summarise(mean(m_active_time)) ``` ##Merging @@ -131,7 +133,12 @@ merge <- dplyr::full_join(instructor_week, student_week, "week") Visualize the relationship between these two variables (mean motivation and mean instructor activity) with the "plot" command and then run a Pearson correlation test (hint: cor.test()). Write the code for the these commands below: ```{r} - + plot(student_week,instructor_week) + x <- c(1,2,3) + y <- c(6913.25, 6240.28571428571,5956.14285714286) + cor.test(x,y) ``` + + Fnally save your markdown document and your plot to this folder and comit, push and pull your repo to submit. diff --git a/Class 7.RData b/Class 7.RData new file mode 100644 index 0000000..c0f1b89 Binary files /dev/null and b/Class 7.RData differ diff --git a/Class7.Rproj b/Class7.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/Class7.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/R markdown.Rmd b/R markdown.Rmd new file mode 100644 index 0000000..ef582d7 --- /dev/null +++ b/R markdown.Rmd @@ -0,0 +1,39 @@ +--- +title: "Markdown" +author: "Joonyoung Park" +date: "9/27/2016" +output: html_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 cars} +summary(cars) +``` + +## Including Plots + +You can also embed plots, for example: + +```{r pressure, echo=FALSE} +plot(pressure) +``` + +Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. + +```{r cars} +summary (cars) +``` + +```{r pressure, echo=FALSE} +plot(pressure) +``` + diff --git a/R_markdown.html b/R_markdown.html new file mode 100644 index 0000000..05d9d2c --- /dev/null +++ b/R_markdown.html @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + +Markdown + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+

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 http://rmarkdown.rstudio.com.

+

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:

+
summary(cars)
+
##      speed           dist       
+##  Min.   : 4.0   Min.   :  2.00  
+##  1st Qu.:12.0   1st Qu.: 26.00  
+##  Median :15.0   Median : 36.00  
+##  Mean   :15.4   Mean   : 42.98  
+##  3rd Qu.:19.0   3rd Qu.: 56.00  
+##  Max.   :25.0   Max.   :120.00
+
+
+

Including Plots

+

You can also embed plots, for example:

+

+

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

+

summary (iris) plot (iris)

+
+ + + + +
+ + + + + + + + diff --git a/Rplot02.jpeg b/Rplot02.jpeg new file mode 100644 index 0000000..ad8f919 Binary files /dev/null and b/Rplot02.jpeg differ diff --git a/Rplot03.jpeg b/Rplot03.jpeg new file mode 100644 index 0000000..4ffdf86 Binary files /dev/null and b/Rplot03.jpeg differ