Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj
.user
.Rhistory
.RData
.Ruserdata
137 changes: 0 additions & 137 deletions Class 7 Instructions.Rmd

This file was deleted.

10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Class 7
Instructions & materials for assignment 3
# TIDYR and DPLYR

Please fork this repository and open it in RStudio. Inside you will find an R Markdown document that contains the instructions for the assignment on data tidying.

Please complete the assignment before class on Thursday.

Good luck!
Packages used: "tidyr" and "dplyr"
Activity to Manipulate and tidy data using the 2 packages
72 changes: 72 additions & 0 deletions dplyr_tidyr.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: tidyr and dplyr to tidy data
author: Charles Lang
sub author: Shreya Goel
date: February 13, 2016
Data Rights: Charles Lang
---

Data used was collected from the class and data generated from the instructor wearing a wristband activity tracker.

```{r Install the packages}
install.packages("tidyr", "dplyr")
library(tidyr, dplyr) #Load packages
```

```{r Read the Instructor Data}
data_wide <- read.table(".../instructor_activity_wide.csv", sep = ",", header = TRUE)
```

```{r Data manipulation - Instructor Data}
data_long <- gather(data_wide, date, variables)
names(data_long) <- c("variables", "date", "measure")
instructor_data <- spread(data_long, variables, measure)
```

```{r Student Data}
student_data <- read.table(".../student_activity.csv", sep = ",", header = TRUE)
student_data <- spread(student_data, variable, measure)
```

```{r Filter data from second class}
student_data_2 <- dplyr::filter(student_data, date == 20160204)
```

```{r Filter/Subset the data which includes only those students who are at table #4}
student_data_3 <- dplyr::filter(student_data, table == 4)
```

```{r Add new Features/Variables}
instructor_data <- dplyr::mutate(instructor_data, total_sleep = s_deep + s_light)
```

```{r Select the total sleep variable}
instructor_sleep <- dplyr::select(instructor_data, total_sleep)
```

```{r create a new variable that groups data}
instructor_data <- dplyr::mutate(instructor_data, week = dplyr::ntile(date, 3))
```

```{r Manipulating the Student Data}
student_data <- dplyr::mutate(student_data, week = dplyr::ntile(date, 3))
```

```{r Summarize Student Data}
student_data %>% dplyr::summarise(mean(motivation))
student_data %>% dplyr::group_by(date) %>% dplyr::summarise(mean(motivation)) # Breaking down the data by week
```

```{r Group Data by Week}
student_week <- student_data %>% dplyr::group_by(week) %>% dplyr::summarise(mean(motivation)) #group by weeks
instructor_week <- instructor_data %>% dplyr::group_by(week) %>% dplyr::summarise(mean(m_active_time))
```

```{r Merge the data}
merge <- dplyr::full_join(instructor_week, student_week, "week")
```

```{r Visualize the data}
plot(merge$`mean(m_active_time)`, merge$`mean(motivation)`)
cor.test(merge$`mean(m_active_time)`, merge$`mean(motivation)`)
```
File renamed without changes.