forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject1.R
16 lines (13 loc) · 810 Bytes
/
project1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
oldd <- setwd("~/Documents/teaching/coursera/Exploratory Data Analysis/projects/ExData_Plotting1")
if (!file.exists("../hh2.rda")) {
# read data, assume 2,100,000 lines and most columns as numeric; "?" is additional NA string
hh <- read.csv("../household_power_consumption.txt", sep=";", colClasses = c("character", "character", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric"), nrows=2100000, na.strings=c("NA", "na", "?"))
# convert Date and Time to POSIXct, select data for valid dates according to instruction
hh$DateTime <- as.POSIXct(strptime(paste(hh$Date, hh$Time), "%d/%m/%Y %H:%M:%S"))
hh$Date2 <- as.Date(hh$DateTime)
hh2 <- subset(hh, hh$Date2 >= "2007-02-01" & hh$Date2 <= "2007-02-02")
# rm(hh)
save("hh2", file="../hh2.rda")
} else {
load("../hh2.rda")
}