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:

Introduction

It is now possible to collect a large amount of data about personal movement using activity monitoring devices such as a Fitbit, Nike Fuelband, or Jawbone Up. These type of devices are part of the “quantified self” movement – a group of enthusiasts who take measurements about themselves regularly to improve their health, to find patterns in their behavior, or because they are tech geeks. But these data remain under-utilized both because the raw data are hard to obtain and there is a lack of statistical methods and software for processing and interpreting the data.

This assignment makes use of data from a personal activity monitoring device. This device collects data at 5 minute intervals through out the day. The data consists of two months of data from an anonymous individual collected during the months of October and November, 2012 and include the number of steps taken in 5 minute intervals each day.

The data for this assignment can be downloaded from the course web site:

The variables included in this dataset are:

steps: Number of steps taking in a 5-minute interval (missing values are coded as 𝙽𝙰) date: The date on which the measurement was taken in YYYY-MM-DD format interval: Identifier for the 5-minute interval in which measurement was taken The dataset is stored in a comma-separated-value (CSV) file and there are a total of 17,568 observations in this dataset.

The.csv file is stored in the working directory.

Reading csv Data from the .csv file and processing

activity <- read.csv("activity.csv")
# Setting date format to help get the weekdays of the dates

activity$date <- as.POSIXct(activity$date, "%Y%m%d")

# Getting the days of all the dates on the dataset
day <- weekdays(activity$date)

# Combining the dataset with the weekday of the dates
activity <- cbind(activity, day)

# Viewing the processed data
summary(activity)
> # Viewing the processed data
> summary(activity)
 steps              date                    interval            day           
 Min.   :  0.00         Min.   :2012-10-01          Min.   :   0.0      Length:17568      
 1st Qu.:  0.00     1st Qu.:2012-10-16      1st Qu.: 588.8      Class :character  
 Median :  0.00      Median :2012-10-31     Median :1177.5      Mode  :character  
 Mean   : 37.38     Mean   :2012-10-31          Mean   :1177.5                     
 3rd Qu.: 12.00     3rd Qu.:2012-11-15      3rd Qu.:1766.2                     
 Max.   :806.00     Max.   :2012-11-30          Max.   :2355.0                     
 NA's   :2304   

What is mean total number of steps taken per day?

  1. Calculate the total number of steps taken per day
# Calculating total steps taken on a day
activityTotalSteps <- with(activity, aggregate(steps, by = list(date), sum, na.rm = TRUE))
# Changing col names
names(activityTotalSteps) <- c("Date", "Steps")
# Converting the data set into a data frame to be able to use ggplot2
totalStepsdf <- data.frame(activityTotalSteps)
head(totalStepsdf)

Date Steps

##1 2012-10-01 0 ##2 2012-10-02 126 ##3 2012-10-03 11352 ##4 2012-10-04 12116 ##5 2012-10-05 13294 ##6 2012-10-06 15420


1.  Make a histogram of the total number of steps taken each day.

``` r
# Plotting a histogram using ggplot2
g <- ggplot(totalStepsdf, aes(x = Steps)) + geom_histogram(breaks = seq(0, 25000, by = 2500), fill = "#83CAFF", col = "black") +  ylim(0, 30) + xlab("Total Steps Taken Per Day") + ylab("Frequency") + ggtitle("Total Number of Steps Taken on a Day") + theme_calc(base_family = "serif")

print(g)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.