forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_data.R
24 lines (19 loc) · 829 Bytes
/
load_data.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Load dataset into R
date_time <- function(date, time) {
return (strptime(paste(date, time), "%d/%m/%Y %H:%M:%S"))
}
load_data <- function() {
filename <- "household_power_consumption.txt"
df <- read.table(filename,
header=TRUE,
sep=";",
colClasses=c("character", "character", rep("numeric",7)),
na="?")
# convert date and time variables to Date/Time class
df$Time <- strptime(paste(df$Date, df$Time), "%d/%m/%Y %H:%M:%S")
df$Date <- as.Date(df$Date, "%d/%m/%Y")
# only use data from the dates 2007-02-01 and 2007-02-02
dates <- as.Date(c("2007-02-01", "2007-02-02"), "%Y-%m-%d")
df <- subset(df, Date %in% dates)
return(df)
}