I am currently doing a “Playable Data” course on Coursera, and one of the questions is asking middle and middle grades per day, I have it, but when I confirm it using the summary function, the summary version of the Intermediate and Median is different. I run this through knitr
Why was that? ** below is a show of all my scripts, including a link to the raw data:
#
target_url <- "http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip"
target_localfile = "ActivityMonitoringData.zip"
if (!file.exists(target_localfile)) {
download.file(target_url, destfile = target_localfile)
}
Unzip the file to the temporary directory
unzip(target_localfile, exdir="extract", overwrite=TRUE)
List the extracted files
list.files("./extract")
#
Load the extracted data into R
activity.csv <- read.csv("./extract/activity.csv", header = TRUE)
activity1 <- activity.csv[complete.cases(activity.csv),]
str(activity1)
#
#
#
#
Use a histogram to view the number of steps taken each day
histData <- aggregate(steps ~ date, data = activity1, sum)
h <- hist(histData$steps, # Save histogram as object
breaks = 11, # "Suggests" 11 bins
freq = T,
col = "thistle1",
main = "Histogram of Activity",
xlab = "Number of daily steps")
Obtain the Mean and Median of the daily steps
steps <- histData$steps
mean(steps)
#
median(steps)
#
summary(histData$steps)
#
#
summary(steps)
#
#
sessionInfo()
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
Chris source
share