Skip to content

Latest commit

 

History

History
127 lines (84 loc) · 2.72 KB

PA1_template.md

File metadata and controls

127 lines (84 loc) · 2.72 KB
title output
Reproducible Research: Peer Assessment 1
html_document
keep_md
true

Loading and preprocessing the data

library(dplyr)
library(xtable)
library(lattice)
library(lubridate)
data <- read.csv("activity.csv")

What is mean total number of steps taken per day?

stepsPerDay <- data %>%
      group_by(date) %>%
      summarize(tot = sum(steps, na.rm = T))

hist(stepsPerDay$tot, main = "Histogram of Steps per Day", xlab = "Steps per Day")

plot of chunk unnamed-chunk-2

dtMean <- round(mean(stepsPerDay$tot),digits = 2)
dtMedian <- median(stepsPerDay$tot)

Mean: 9354.23

Median: 10395

What is the average daily activity pattern?

stepsPerTime <- data %>%
      group_by(interval) %>%
      summarize(avg = mean(steps, na.rm=T))

plot(stepsPerTime$interval,stepsPerTime$avg,type = "l",main="Avg Steps per Interval",xlab="5 min interval",ylab="Avg Steps")

plot of chunk unnamed-chunk-3

dtMax <- filter(stepsPerTime, avg == max(stepsPerTime$avg)) %>% select(interval)

Interval with highest average steps: 835

Imputing missing values

I took the interval's average in order to fill in NA values. A better method might be to break intervals down by day type

NArows <- data %>%
      filter(is.na(steps))
naRowCount <- count(NArows)

Rows with NA: 2304

nonNArows <- data %>%
      filter(!is.na(steps))
nonNArows$steps <- as.numeric(nonNArows$steps)

avgData <- select(NArows, -steps) %>% 
      inner_join(stepsPerTime) %>%
      select(avg, date, interval)
## Joining by: "interval"
colnames(avgData) <- colnames(nonNArows)

fullData <- dplyr::union(nonNArows,avgData)

stepsPerDayFull <- fullData %>%
      group_by(date) %>%
      summarize(tot = sum(steps, na.rm = T))

hist(stepsPerDayFull$tot, main = "Histogram of Steps per Day w/ Avg for NAs", xlab = "Steps per Day")

plot of chunk unnamed-chunk-5

dtMean <- round(mean(stepsPerDay$tot),digits = 2)
dtMedian <- median(stepsPerDay$tot)

Mean w/ Interval Avg for NAs: 9354.23

Median w/ Interval Avg for NAs: 10395

Are there differences in activity patterns between weekdays and weekends?

fullData <- mutate(fullData,dayType = ifelse(wday(as.Date(fullData$date),T) == c("Sun","Sat"),"Weekend","Weekday")) %>%
      group_by(dayType, interval) %>%
      summarize(avg = mean(steps)) %>%
      arrange(interval) 

xyplot(avg ~ interval | dayType, fullData, type="l", layout = c(1,2), xlab = "Interval", ylab="Average Steps",main="Average Steps by Day Type")

plot of chunk unnamed-chunk-6