You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
library(plyr)
# calculate the total number of missing vlaues in the datasetmissing_data= subset(mydata, is.na(steps))
print (nrow(missing_data))
## [1] 2304
# filling all missing values with mean for that 5-minute interval.edata= merge(mydata, subset(ddata, select=c("interval","mean")), by="interval")
for(iin1:nrow(edata)){
if (is.na(edata$steps[i]) ==TRUE) {
edata$steps[i] =edata$mean[i]
}
}
edata= subset(edata, select=c("steps", "date", "interval"))
summary(edata)
## steps date interval
## Min. : 0.00 2012-10-01: 288 Min. : 0.0
## 1st Qu.: 0.00 2012-10-02: 288 1st Qu.: 588.8
## Median : 0.00 2012-10-03: 288 Median :1177.5
## Mean : 37.38 2012-10-04: 288 Mean :1177.5
## 3rd Qu.: 27.00 2012-10-05: 288 3rd Qu.:1766.2
## Max. :806.00 2012-10-06: 288 Max. :2355.0
## (Other) :15840
## date steps
## 2012-10-01: 1 Min. : 41
## 2012-10-02: 1 1st Qu.: 9819
## 2012-10-03: 1 Median :10766
## 2012-10-04: 1 Mean :10766
## 2012-10-05: 1 3rd Qu.:12811
## 2012-10-06: 1 Max. :21194
## (Other) :55
mean_steps2= mean(c2data$steps)
median_steps2= median(c2data$steps)
hist(c2data$steps, main="Total steps taken per day after filling NA", xlab="Steps")
print(mean_steps2)
## [1] 10766.19
print(median_steps2)
## [1] 10766.19
Are there differences in activity patterns between weekdays and weekends?
library(plyr)
# add a new variable for weekdayedata$day<- as.factor(ifelse(weekdays(as.Date(edata$date)) %in% c("Staturday","Sunday"), "Weekend", "Weekday"))
summary(edata)
## steps date interval day
## Min. : 0.00 2012-10-01: 288 Min. : 0.0 Weekday:15264
## 1st Qu.: 0.00 2012-10-02: 288 1st Qu.: 588.8 Weekend: 2304
## Median : 0.00 2012-10-03: 288 Median :1177.5
## Mean : 37.38 2012-10-04: 288 Mean :1177.5
## 3rd Qu.: 27.00 2012-10-05: 288 3rd Qu.:1766.2
## Max. :806.00 2012-10-06: 288 Max. :2355.0
## (Other) :15840