R Reproducible Research course project课程练习

本报告使用个人活动监测设备收集的数据,分析了匿名个体在2012年10月和11月两个月内的日常活动模式。通过数据预处理、缺失值填充等步骤,探究了每日步数变化、平均活动模式及工作日与周末活动差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原版Rmd代码在这个github地址

title: “Reproducible Research: Peer Assessment 1”
author: “shanesu”
date: “2016年10月12日”
output:
html_document:
keep_md: true

Introduction

This assignment makes use of data from a personal activity monitoring device. This device collects data at 5 minute intervals through out the day. The data consists of two months of data from an anonymous individual collected during the months of October and November, 2012 and include the number of steps taken in 5 minute intervals each day.

The data for this assignment can be downloaded from the course web site:

Dataset: Activity monitoring data [52K]
The variables included in this dataset are:

  • steps: Number of steps taking in a 5-minute interval (missing values are coded as NA)
  • date: The date on which the measurement was taken in YYYY-MM-DD format
  • interval: Identifier for the 5-minute interval in which measurement was taken

The dataset is stored in a comma-separated-value (CSV) file and there are a total of 17,568 observations in this dataset.

Loading and preprocessing the data

 knitr::opts_chunk$set(echo = TRUE)
temp <- tempfile()
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip", destfile = temp )
unzip(temp, "activity.csv")
activity<-read.csv("activity.csv")
head(activity)

What is mean total number of steps taken per day?

stepsum<-tapply(activity$steps,activity$date,sum)
hist(stepsum)
the mean
mean(stepsum,na.rm = TRUE)
the median
median(stepsum,na.rm = TRUE)

What is the average daily activity pattern?

stepave<-aggregate(steps~interval,data = activity,FUN = mean,na.rm=TRUE)
plot(stepave$interval,stepave$steps)
which max
stepave$interval[which.max(stepave$steps)]

Imputing missing values

cleardate<-activity
addmiss<-function(mystep,myinterval){
  if(is.na(mystep))
      newvalue<-stepave$steps[which(stepave$interval==myinterval)]
  else
      newvalue<-mystep
  return(newvalue)
}
cleardate$steps<-mapply(addmiss,cleardate$steps,cleardate$interval)
summary(cleardate)
show the new hist
hist(tapply(cleardate$steps,cleardate$date,sum))

Are there differences in activity patterns between weekdays and weekends?

cleardate$date<-as.Date(cleardate$date)
library(ggplot2)
isweekday<-function(idate){
   if (weekdays(idate) %in% c("星期日", "星期六"))
       return("weekend")
   else
       return("weekday")
}
cleardate$daytype<-mapply(isweekday,cleardate$date)
ggplot(cleardate)+geom_point(aes(x=interval,y=steps,colour=daytype))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值