head(data)
## steps date interval
## 1 NA 2012-10-01 0
## 2 NA 2012-10-01 5
## 3 NA 2012-10-01 10
## 4 NA 2012-10-01 15
## 5 NA 2012-10-01 20
## 6 NA 2012-10-01 25
### Mean
## # A tibble: 61 x 3
## date mean median
## <chr> <dbl> <dbl>
## 1 2012-10-01 NA NA
## 2 2012-10-02 0.438 0
## 3 2012-10-03 39.4 0
## 4 2012-10-04 42.1 0
## 5 2012-10-05 46.2 0
## 6 2012-10-06 53.5 0
## 7 2012-10-07 38.2 0
## 8 2012-10-08 NA NA
## 9 2012-10-09 44.5 0
## 10 2012-10-10 34.4 0
## # ... with 51 more rows
## # i Use `print(n = ...)` to see more rows
## Warning in plot.xy(xy, type, ...): plot type 'line' will be truncated to first
## character
maximum_which<-data%>%group_by(date)%>%summarise_at(vars(steps), list(max = which.max))
print(mean(maximum_which$max))
## [1] 144.9434
sum(data$steps%>%is.na)
## [1] 2304
data$steps <- data$steps %>% replace(is.na(.), mean(data$steps,na.rm=T))
print(data$steps%>%head)
## [1] 37.3826 37.3826 37.3826 37.3826 37.3826 37.3826
total_per_day<-data%>%group_by(date)%>%summarise_at(vars(steps), list(total = sum))
hist(total_per_day$total,xlab="Total Steps",main="Histogram of total steps")
### Panel plot
summary(total_per_day)
## date total
## Length:61 Min. : 41
## Class :character 1st Qu.: 9819
## Mode :character Median :10766
## Mean :10766
## 3rd Qu.:12811
## Max. :21194
weekdays1 <- c('lunes', 'martes', 'miércoles', 'jueves', 'viernes')
#Use `%in%` and `weekdays` to create a logical vector
#convert to `factor` and specify the `levels/labels`
data$weekday <- factor((weekdays(as.Date(data$date)) %in% weekdays1),
levels=c(FALSE, TRUE), labels=c('weekend', 'weekday'))
average<-data%>%group_by(weekday,date)%>%summarise_at(vars(steps), list(mean = mean))
par(mfrow=c(1,2))
plot(average[average$weekday=="weekday",]$mean,type = "l",ylab = "mean",main = "Weekday")
abline(h=average[average$weekday=="weekday",]$mean%>%mean)
plot(average[average$weekday=="weekend",]$mean,type = "l",ylab = "mean",main="Weekend")
abline(h=average[average$weekday=="weekend",]$mean%>%mean)