forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPowerConsumptionSampleData.R
More file actions
29 lines (25 loc) · 1.7 KB
/
getPowerConsumptionSampleData.R
File metadata and controls
29 lines (25 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# assignment 1
# read data file
powerConsumption <- read.table("household_power_consumption.txt",
header = TRUE,
sep = ';',
na.strings = "?",
colClasses=c("character","character","numeric","numeric","numeric","numeric","numeric","numeric","numeric"))
# extract just the two days of interest
pwrSampleDays <- powerConsumption[(powerConsumption$Date == "1/2/2007") | (powerConsumption$Date == "2/2/2007"),]
# paste together Date and Time fields to new variable "dateTime" for graphing time series data
pwrSampleDays$dateTime <- paste(pwrSampleDays$Date, pwrSampleDays$Time)
pwrSampleDays$Date <- as.Date(pwrSampleDays$Date, format = "%d/%m/%Y")
pwrSampleDays$dateTime <- strptime(pwrSampleDays$dateTime, format = "%d/%m/%Y %H:%M:%S")
str(pwrSampleDays) # check it looks OK :)
# 'data.frame': 2880 obs. of 10 variables:
# $ Date : Date, format: "2007-02-01" "2007-02-01" "2007-02-01" "2007-02-01" ...
# $ Time : chr "00:00:00" "00:01:00" "00:02:00" "00:03:00" ...
# $ Global_active_power : num 0.326 0.326 0.324 0.324 0.322 0.32 0.32 0.32 0.32 0.236 ...
# $ Global_reactive_power: num 0.128 0.13 0.132 0.134 0.13 0.126 0.126 0.126 0.128 0 ...
# $ Voltage : num 243 243 244 244 243 ...
# $ Global_intensity : num 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1 ...
# $ Sub_metering_1 : num 0 0 0 0 0 0 0 0 0 0 ...
# $ Sub_metering_2 : num 0 0 0 0 0 0 0 0 0 0 ...
# $ Sub_metering_3 : num 0 0 0 0 0 0 0 0 0 0 ...
# $ dateTime : POSIXlt, format: "2007-02-01 00:00:00" "2007-02-01 00:01:00" "2007-02-01 00:02:00" "2007-02-01 00:03:00" ...