-
Notifications
You must be signed in to change notification settings - Fork 37.1k
/
Copy pathAMNA work
56 lines (39 loc) · 1.73 KB
/
AMNA work
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
---
title: "Reproducible Research: Peer Assessment 1"
output:
html_document:
keep_md: true
---
# Read in the dataset
steps_data \<-
read.csv("C:\\Users\\amnay\\AppData\\Local\\Temp\\Rar\$DIa4616.49842\\activity.csv")
# Convert date column to date format
steps_data$date <- as.Date(steps_data$date)
# Add a column for day of the week
library(lubridate) steps_data$day_of_week <- weekdays(steps_data$date)
# Add a column for weekend
steps_data$weekend <- ifelse(steps_data$day_of_week %in% c("Sat",
"Sun"), 1, 0) \# Calculate total steps per day library(magrittr)
total_steps_per_day \<- steps_data %\>% group_by(date) %\>%
summarise(total_steps = sum(steps))
# Plot the histogram
ggplot(total_steps_per_day, aes(x = total_steps)) +
geom_histogram(binwidth = 1000, color = "black", fill = "white") +
ggtitle("Histogram of Total Steps Taken Each Day") + xlab("Total
Steps") + ylab("Frequency")
\# Calculate mean and median steps per day mean_steps_per_day \<-
mean(total_steps_per_day$total_steps) median_steps_per_day <- median(total_steps_per_day$total_steps)
# Print the results
cat("Mean Steps per Day:", mean_steps_per_day, "\n") cat("Median Steps
per Day:", median_steps_per_day, "\n")
# Calculate average steps per 5-minute interval
average_steps_per_interval \<- steps_data %\>% group_by(interval) %\>%
summarise(average_steps = mean(steps))
# Plot the time series
ggplot(average_steps_per_interval, aes(x = interval, y =
average_steps)) + geom_line(color = "red") + ggtitle("Time Series Plot
of Average Steps Taken") + xlab("5-Minute Interval") + ylab("Average
Steps")
\# Find the 5-minute interval with maximum average steps max_interval
\<- average_steps_per_interval %\>% filter(average_steps ==
max(average_steps)) %\>% pull(interval)