forked from rdpeng/RepData_PeerAssessment1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
35,604 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Reproducible Research: Peer Assessment 1 | ||
|
||
|
||
## Loading and preprocessing the data | ||
|
||
### Load the activity data | ||
Extract the zip file on your OS and load the data file 'activity.csv' in R. | ||
|
||
|
||
```r | ||
dat <- read.csv("activity.csv", sep = ",", header = TRUE) | ||
``` | ||
|
||
### Process the data | ||
Factor the 'date' field for further analysis. | ||
|
||
|
||
```r | ||
dat <- transform(dat, date = factor(date)) | ||
``` | ||
|
||
|
||
## What is mean total number of steps taken per day? | ||
|
||
### Histogram of the total number of steps taken each day | ||
|
||
```r | ||
library(ggplot2) | ||
steps.per.day <- tapply(dat$steps, dat$date, sum, na.rm = TRUE) | ||
steps <- data.frame(steps.per.day, names(steps.per.day)) | ||
hist(steps$steps.per.day, breaks = length(steps.per.day), xlab = " Number of Steps Each Day", main = "Histogram of Steps Taken Each Day") | ||
``` | ||
|
||
![plot of chunk histogram.steps.each.day](./PA1_template_files/figure-html/histogram.steps.each.day.png) | ||
|
||
--- | ||
![Histogram of steps taken each day](instructions_fig/histStepsEachDay.png) | ||
--- | ||
|
||
### Mean and median total number of steps taken per day | ||
|
||
```r | ||
mu <- mean(steps.per.day, na.rm = TRUE) | ||
median <- median(steps.per.day, na.rm = TRUE) | ||
``` | ||
Mean of total number of steps taken per day is **9354.2295**. | ||
|
||
Median of total numnber of steps taken per day is **10395**. | ||
|
||
|
||
## What is the average daily activity pattern? | ||
|
||
### Average Steps taken for each interval across all days | ||
|
||
```r | ||
dat <- transform(dat, interval = ordered(as.numeric(interval))) | ||
avg.steps.per.interval <- tapply(dat$steps, dat$interval, mean, na.rm = TRUE) | ||
avg.steps <- data.frame(steps = avg.steps.per.interval, interval = as.numeric(names(avg.steps.per.interval))) | ||
plot(x = avg.steps$interval, y = avg.steps$steps, type = "l", xlab = "Interval", ylab = "Steps", main = "Average Steps per Interval") | ||
``` | ||
|
||
![plot of chunk avgStepsPerInterval](./PA1_template_files/figure-html/avgStepsPerInterval.png) | ||
|
||
--- | ||
![Average Steps Per Interval](instructions_fig/avgStepsPerInterval.png) | ||
--- | ||
|
||
### Overall Maximum Steps Interval Identifier | ||
|
||
```r | ||
interval.id <- avg.steps[which.max(avg.steps$steps), 2] | ||
``` | ||
Id **835** is the 5-minute interval id, on average across all the days in the dataset, which contains the maximum number of steps. | ||
|
||
## Imputing missing values | ||
|
||
|
||
|
||
## Are there differences in activity patterns between weekdays and weekends? |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
x <- rnorm(100, sd =0.5) | ||
mean(x, na.rm = TRUE) | ||
setwd("/data/courses/reproduce-research/work/reproduce-research/RepData_PeerAssessment1") | ||
dat <- read.csv("activity.csv", header=TRUE) | ||
dat <- transform(dat, date <- factor(date)) | ||
str(dat) | ||
|
||
steps.per.day <- tapply(dat$steps, dat$date, sum, na.rm = TRUE) | ||
str(steps.per.day) | ||
names(steps.per.day) | ||
steps.per.day["2012-10-02"] | ||
steps <- data.frame(steps.per.day, names(steps.per.day)) | ||
hist(steps$steps.per.day, breaks = length(steps.per.day), xlab = " Number of Steps Each Day", main = "Histogram of Steps Taken Each Day") | ||
mu <- mean(steps.per.day, na.rm = TRUE) | ||
median <- median(steps.per.day, na.rm = TRUE) | ||
mu | ||
median | ||
|
||
dat <- transform(dat, interval = ordered(as.numeric(interval))) | ||
str(dat) | ||
avg.steps.per.interval <- tapply(dat$steps, dat$interval, mean, na.rm = TRUE) | ||
head(avg.steps.per.interval) | ||
names(avg.steps.per.interval) | ||
avg.steps <- data.frame(steps = avg.steps.per.interval, interval = as.numeric(names(avg.steps.per.interval))) | ||
plot(x = avg.steps$interval, y = avg.steps$steps, type = "l", xlab = "Interval", ylab = "Steps", main = "Average Steps per Interval") | ||
|
||
avg.steps[which.max(avg.steps$steps), 2] | ||
|
||
foo <- function(x = 1, y = 2) c(x, y) | ||
bar <- function(n, x) replicate(n, foo(x = x)) | ||
bar(5, x = 3) | ||
x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE)) | ||
x |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.