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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
20 changes: 12 additions & 8 deletions Class 7 Instructions.Rmd → ANSWERS.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Assignment 3"
author: "Charles Lang"
date: "February 13, 2016"
author: "Sam Pepe"
date: "September 28 2016"
---
##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.

Expand Down Expand Up @@ -59,7 +59,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}

newstud<-spread(student_data,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.
Expand All @@ -75,7 +75,7 @@ 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:

```{r}

student_tab4<-dplyr::filter(newstud,table==4)
```

##Make a new variable
Expand All @@ -89,7 +89,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::transmute(instructor_data,total_sleep = s_deep + s_light )
```

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:
Expand All @@ -100,7 +100,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(newstud,week=dplyr::ntile(date, 3))
```

##Sumaraizing
Expand All @@ -117,7 +117,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<-student_data %>% dplyr::group_by(week) %>% dplyr::summarise(mean(motivation))
instructor_week<-instructor_data %>% dplyr::group_by(week) %>% dplyr::summarise(mean(m_active_time))
```

##Merging
Expand All @@ -131,7 +132,10 @@ 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(instructor_week,student_week)
ins<-subset(instructor_week,select=-week)
stu<-subset(student_week,select=-week)
cor(ins,stu,method="pearson")
```

Fnally save your markdown document and your plot to this folder and comit, push and pull your repo to submit.
30 changes: 30 additions & 0 deletions Class7.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: "Class7"
author: "Sam"
date: "September 28, 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 <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:

```{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.
13 changes: 13 additions & 0 deletions class7.Rproj
Original file line number Diff line number Diff line change
@@ -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
17 changes: 16 additions & 1 deletion instructor_activity_wide.csv
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
variables,X20160121,X20160122,X20160123,X20160124,X20160125,X20160126,X20160127,X20160128,X20160129,X20160130,X20160131,X20160201,X20160202,X20160203,X20160204,X20160205,X20160206,X20160207,X20160208,X20160209,X20160210,X20160211alcoholic_beverages,1,0,0,0,0,3,0,0,2,0,0,1,1,0,0,0,0,1,0,2,0,1m_active_time,8239,9429,949,1953,6790,8227,6973,12746,7498,4843,5788,9127,2509,5041,8876,3017,4082,8311,6654,941,6725,11963m_inactive_time,27309,24275,28167,28171,25854,25219,25714,27731,25853,25762,28173,23773,26662,26093,24376,27100,28048,24452,25914,6594,25099,26111m_lcat,1195,1947,380,882,1264,2132,1198,1887,884,1705,1381,1070,314,944,1760,501,943,1889,1382,437,700,1377m_steps,14422,16173,2207,3444,11700,14067,11931,13641,13275,8583,10840,16100,4299,9066,16724,5549,7468,14896,11798,1871,10972,11606m_steps_3am,27,92,0,16,41,0,104,45,2601,47,1557,146,66,11,0,17,36,10,63,65,0,0m_total_calories_spent,2451.104807,2559.086301,1829.067794,1878.049287,2315.03078,2452.012273,2279.993766,2841.97526,2399.956753,2140.938246,2293.919739,2522.901232,1968.882725,2174.864218,2634.845712,2030.827205,2151.808698,2522.790191,2377.771684,1810.753177,1717.73467,2810.716164s_asleep_time,899,9337,7399,1811,4359,-443,1750,3506,9772,4684,5420,3165,2582,6016,2608,1367,566,4574,7531,8348,4328,6788s_awake,1434,1294,783,5041,6816,1234,1441,908,600,2994,7869,441,1535,2617,2831,4028,2049,1198,1001,783,9922,1000s_awake_time,25107,27231,36436,32257,23282,25110,25194,25095,32520,41467,41730,25829,28434,28126,26198,32181,27104,37336,26625,31083,4277,25200s_awakenings,2,0,0,2,1,1,2,0,0,2,5,0,1,2,2,3,1,0,0,0,0,0s_bedtime,599,8737,6799,1211,1841,-1043,1150,2906,9172,4084,4820,2724,1982,5416,2008,639,-34,3974,6931,7748,8255,1100s_deep,7981,3596,10309,6301,6670,11858,8676,4329,7888,13315,7959,7968,9475,8629,7151,12367,7474,14853,6703,6379,8600,9820s_duration,23074,17894,29037,26005,14749,24919,22689,21589,22748,34415,29041,22664,25445,20498,22268,27760,25940,32762,19094,22735,22837,25200s_light,15093,14298,18728,19704,8079,13061,14013,17260,14860,21100,21082,14696,15970,11869,15117,15393,18466,17909,12391,16356,18558,12778
variables,20160121,20160122,20160123,20160124,20160125,20160126,20160127,20160128,20160129,20160130,20160131,20160201,20160202,20160203,20160204,20160205,20160206,20160207,20160208,20160209,20160210,20160211
alcoholic_beverages,1,0,0,0,0,3,0,0,2,0,0,1,1,0,0,0,0,1,0,2,0,1
m_active_time,8239,9429,949,1953,6790,8227,6973,12746,7498,4843,5788,9127,2509,5041,8876,3017,4082,8311,6654,941,6725,11963
m_inactive_time,27309,24275,28167,28171,25854,25219,25714,27731,25853,25762,28173,23773,26662,26093,24376,27100,28048,24452,25914,6594,25099,26111
m_lcat,1195,1947,380,882,1264,2132,1198,1887,884,1705,1381,1070,314,944,1760,501,943,1889,1382,437,700,1377
m_steps,14422,16173,2207,3444,11700,14067,11931,13641,13275,8583,10840,16100,4299,9066,16724,5549,7468,14896,11798,1871,10972,11606
m_steps_3am,27,92,0,16,41,0,104,45,2601,47,1557,146,66,11,0,17,36,10,63,65,0,0
m_total_calories_spent,2451.104807,2559.086301,1829.067794,1878.049287,2315.03078,2452.012273,2279.993766,2841.97526,2399.956753,2140.938246,2293.919739,2522.901232,1968.882725,2174.864218,2634.845712,2030.827205,2151.808698,2522.790191,2377.771684,1810.753177,1717.73467,2810.716164
s_asleep_time,899,9337,7399,1811,4359,-443,1750,3506,9772,4684,5420,3165,2582,6016,2608,1367,566,4574,7531,8348,4328,6788
s_awake,1434,1294,783,5041,6816,1234,1441,908,600,2994,7869,441,1535,2617,2831,4028,2049,1198,1001,783,9922,1000
s_awake_time,25107,27231,36436,32257,23282,25110,25194,25095,32520,41467,41730,25829,28434,28126,26198,32181,27104,37336,26625,31083,4277,25200
s_awakenings,2,0,0,2,1,1,2,0,0,2,5,0,1,2,2,3,1,0,0,0,0,0
s_bedtime,599,8737,6799,1211,1841,-1043,1150,2906,9172,4084,4820,2724,1982,5416,2008,639,-34,3974,6931,7748,8255,1100
s_deep,7981,3596,10309,6301,6670,11858,8676,4329,7888,13315,7959,7968,9475,8629,7151,12367,7474,14853,6703,6379,8600,9820
s_duration,23074,17894,29037,26005,14749,24919,22689,21589,22748,34415,29041,22664,25445,20498,22268,27760,25940,32762,19094,22735,22837,25200
s_light,15093,14298,18728,19704,8079,13061,14013,17260,14860,21100,21082,14696,15970,11869,15117,15393,18466,17909,12391,16356,18558,12778
59 changes: 59 additions & 0 deletions shiny.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: "Class7"
author: "Sam"
date: "September 28, 2016"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

This R Markdown document is made interactive using Shiny. Unlike the more traditional workflow of creating static reports, you can now create documents that allow your readers to change the assumptions underlying your analysis and see the results immediately.

To learn more, see [Interactive Documents](http://rmarkdown.rstudio.com/authoring_shiny.html).

## Inputs and Outputs

You can embed Shiny inputs and outputs in your document. Outputs are automatically updated whenever inputs change. This demonstrates how a standard R plot can be made interactive by wrapping it in the Shiny `renderPlot` function. The `selectInput` and `sliderInput` functions create the input widgets used to drive the plot.

```{r eruptions, echo=FALSE}
inputPanel(
selectInput("n_breaks", label = "Number of bins:",
choices = c(10, 20, 35, 50), selected = 20),

sliderInput("bw_adjust", label = "Bandwidth adjustment:",
min = 0.2, max = 2, value = 1, step = 0.2)
)

renderPlot({
hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks),
xlab = "Duration (minutes)", main = "Geyser eruption duration")

dens <- density(faithful$eruptions, adjust = input$bw_adjust)
lines(dens, col = "blue")
})
```

## Embedded Application

It's also possible to embed an entire Shiny application within an R Markdown document using the `shinyAppDir` function. This example embeds a Shiny application located in another directory:

```{r tabsets, echo=FALSE}
shinyAppDir(
system.file("examples/06_tabsets", package = "shiny"),
options = list(
width = "100%", height = 550
)
)
```

Note the use of the `height` parameter to determine how much vertical space the embedded application should occupy.

You can also use the `shinyApp` function to define an application inline rather then in an external directory.

In all of R code chunks above the `echo = FALSE` attribute is used. This is to prevent the R code within the chunk from rendering in the document alongside the Shiny components.