-
Notifications
You must be signed in to change notification settings - Fork 0
/
PA1_template.Rmd
76 lines (55 loc) · 2.73 KB
/
PA1_template.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: "Activity Monitor Analysis Assignemt"
author: "Babak Rabie"
date: "November 13, 2015"
output: html_document
---
### 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.
### Data
The data for this assignment can be downloaded from this location:
Dataset: Activity monitoring data [52K]
<https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip>
The variables included in this dataset are:
steps: Number of steps taking in a 5-minute interval (missing values are coded as NA)
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.
### Loading and preprocessing the data
```{r}
data<-read.csv("activity.csv")
data<-subset(data,!is.na(data$steps))
```
### What is mean total number of steps taken per day?
Aggregate the data by date
```{r}
aggrdata<-aggregate(data$steps, by=list(date=data$date),sum)
names(aggrdata)[2]<- "steps"
```
Create a histogram for the number of total number of steps taken each day
```{r}
hist(aggrdata$steps)
```
Calculate mean and median of steps per day
```{r}
mean(aggrdata$steps)
median(aggrdata$steps)
```
###What is the average daily activity pattern?
Make a time series plot (i.e. type = "l") of the 5-minute interval (x-axis) and the average number of steps taken, averaged across all days (y-axis)
1- Aggeregate data by interval
```{r}
aggrIntervals<-aggregate(data$steps, by=list(interval=data$interval),mean)
names(aggrIntervals)[2]<-"Avg. Steps"
```
2- Make a time series plot on aggregated data
```{r}
plot.ts(aggrIntervals$`Avg. Steps`)
```
3- Find the interval with maximum steps
```{r}
MaxIntervalRow<-subset(aggrIntervals,`Avg. Steps` == max(aggrIntervals$`Avg. Steps`))
MaxInterval<-MaxIntervalRow$interval
MaxInterval
```