This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist    
##  Min.   : 4.0   Min.   :  2  
##  1st Qu.:12.0   1st Qu.: 26  
##  Median :15.0   Median : 36  
##  Mean   :15.4   Mean   : 43  
##  3rd Qu.:19.0   3rd Qu.: 56  
##  Max.   :25.0   Max.   :120

You can also embed plots, for example:

plot of chunk unnamed-chunk-2

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Homework 2

  1. Loading the data
setwd("C:/")
activity <-read.csv("./activity.csv")
totalSteps <- aggregate(steps ~ date, data = activity, sum, na.rm = TRUE)
  1. what is mean total number of steps taken per day? histogram
hist(totalSteps$steps,col="blue")

plot of chunk unnamed-chunk-5

mean(totalSteps$steps)
## [1] 10766
median(totalSteps$steps)
## [1] 10765
  1. what is the average daily activity pattern?
stepsInterval <- aggregate(steps ~ interval, data = activity, mean, na.rm = TRUE)
plot(steps ~ interval, data = stepsInterval, type = "l", col="blue")

plot of chunk unnamed-chunk-8

stepsInterval[which.max(stepsInterval$steps), ]$interval
## [1] 835
  1. Imputing missing values
sum(is.na(activity$steps))
## [1] 2304

교수님 이건 안배운거 같아요.

interval2steps <- function(interval) {
    stepsInterval[stepsInterval$interval == interval, ]$steps
}

이건 진짜로 모르겠네요~~

activityFilled <- activity 
count = 0 
for (i in 1:nrow(activityFilled)) {
    if (is.na(activityFilled[i, ]$steps)) {
        activityFilled[i, ]$steps <- interval2steps(activityFilled[i, ]$interval)
        count = count + 1
    }
}
cat("Total ", count, "NA values were filled.\n\r")
## Total  2304 NA values were filled.
## 

요건 약간 익숙해졌네요.

totalSteps2 <- aggregate(steps ~ date, data = activityFilled, sum)
hist(totalSteps2$steps, col="pink")

plot of chunk unnamed-chunk-13

mean(totalSteps$steps)
## [1] 10766
median(totalSteps$steps)
## [1] 10765
  1. Are there differenced in activity patterns between weekdays and weekends?

멘붕

activityFilled$day = ifelse(as.POSIXlt(as.Date(activityFilled$date))$wday%%6 == 
    0, "weekend", "weekday")
activityFilled$day = factor(activityFilled$day, levels = c("weekday", "weekend"))
stepsInterval2 = aggregate(steps ~ interval + day, activityFilled, mean)
library(lattice)
xyplot(steps ~ interval | factor(day), data = stepsInterval2, aspect = 1/2, 
    type = "l", col="green")

plot of chunk unnamed-chunk-17

교수님 다 컨닝했어요. 죄송해요 ㅠㅠ