Skip to content

Commit

Permalink
first commit for PA1.
Browse files Browse the repository at this point in the history
  • Loading branch information
morepj committed Sep 14, 2014
1 parent c052538 commit e61d80d
Show file tree
Hide file tree
Showing 11 changed files with 35,604 additions and 0 deletions.
17,569 changes: 17,569 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions PA1_template.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,64 @@ output:

## 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 loaddata, echo=TRUE}
dat <- read.csv("activity.csv", sep = ",", header = TRUE)
```

### Process the data
Factor the 'date' field for further analysis.

```{r preprocess, echo= TRUE}
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 histogram.steps.each.day, echo = TRUE}
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")
```

---
![Histogram of steps taken each day](instructions_fig/histStepsEachDay.png)
---

### Mean and median total number of steps taken per day
```{r meanAndMedian, echo = TRUE}
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 **`r mu`**.

Median of total numnber of steps taken per day is **`r median`**.


## What is the average daily activity pattern?

### Average Steps taken for each interval across all days
```{r avgStepsPerInterval, echo = TRUE}
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")
```

---
![Average Steps Per Interval](instructions_fig/avgStepsPerInterval.png)
---

### Overall Maximum Steps Interval Identifier
```{r maxStepsInterval, echo = TRUE}
interval.id <- avg.steps[which.max(avg.steps$steps), 2]
```
Id **`r interval.id`** 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

Expand Down
135 changes: 135 additions & 0 deletions PA1_template.html

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions PA1_template.md
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.
33 changes: 33 additions & 0 deletions PA1_template_files/source/temp.R
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
170 changes: 170 additions & 0 deletions README.html

Large diffs are not rendered by default.

Loading

0 comments on commit e61d80d

Please sign in to comment.