Activity monitoring DATA

Loading and preprocessing the data

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
filename <- "Dataset.zip"
if (!file.exists(filename)){
        fileURL <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip"
        download.file(fileURL, filename, method="curl")
} 
if (!file.exists("Factivity")) { 
        unzip(filename) 
}

## SHOW THE LIST OF FILES IN YOUR PATH list.files("./", recursive=TRUE)
xdata <- read.csv("activity.csv", sep = "," ,header = TRUE)

What is mean total number of steps taken per day?

Calculate the total number of steps taken per day

tsbd<-aggregate(steps~date, xdata, sum)

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

Calculate and report the mean and median of the total number of steps taken per day

## [1] 10766.19
## [1] 10765

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

Which 5-minute interval, on average across all the days in the dataset, contains the maximum number of steps?

## [1] 835

Imputing missing values

Calculate and report the total number of missing values in the dataset (i.e. the total number of rows with NAs)

sum(is.na(xdata$steps))
## [1] 2304

Devise a strategy for filling in all of the missing values in the dataset. The strategy does not need to be sophisticated. For example, you could use the mean/median for that day, or the mean for that 5-minute interval, etc.

##Calculating the media for the data
meanasbd <- mean(asbd$steps)

##Replacing values
pdata <- transform(xdata, steps = ifelse(is.na(xdata$steps), yes = meanasbd, no = xdata$steps))

Create a new dataset that is equal to the original dataset but with the missing data filled in.

atsbd <- aggregate(steps~date, pdata, sum)

Make a histogram of the total number of steps taken each day and Calculate and report the mean and median total number of steps taken per day. Do these values differ from the estimates from the first part of the assignment? What is the impact of imputing missing data on the estimates of the total daily number of steps?

Mean

## [1] 10766.19

Median

## [1] 10766.19

Are there differences in activity patterns between weekdays and weekends?

Create a new factor variable in the dataset with two levels – “weekday” and “weekend” indicating whether a given date is a weekday or weekend day.

pdata$date<-as.Date(pdata$date)

ydata<-pdata%>%
        mutate(week = ifelse(weekdays(date)=="Saturday" | weekdays(date)=="Sunday", "Weekend", "Weekday")) %>%
                group_by(week, interval) %>%
                        summarize(tasteps=sum(steps))
## `summarise()` regrouping output by 'week' (override with `.groups` argument)

Make a panel plot containing a time series plot of the 5-minute interval (x-axis) and the average number of steps taken, averaged across all weekday days or weekend days (y-axis). See the README file in the GitHub repository to see an example of what this plot should look like using simulated data.