forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot2.R
More file actions
20 lines (14 loc) · 1.09 KB
/
Copy pathplot2.R
File metadata and controls
20 lines (14 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
setwd("C:\\Projects\\MDataScience\\Exploratory\\Week1Exercise")
powerConsumptionRaw <- read.table("household_power_consumption.txt",na.strings="?", sep=";", header=T, colClasses = c("character", "character","numeric", "numeric", "numeric" , "numeric" , "numeric" , "numeric" , "numeric" ))
newDateTime <- paste (powerConsumptionRaw$Date, powerConsumptionRaw$Time, sep=" ")
convertedDate <- as.Date(strptime(newDateTime, "%d/%m/%Y %H:%M:%S"))
convertedDateTime <- as.POSIXlt(strptime(newDateTime, "%d/%m/%Y %H:%M:%S"))
powerConsumptionCleansed <- cbind(convertedDate, convertedDateTime, powerConsumptionRaw[c(-1,-2)])
dateRangeAbove <- convertedDate >= as.Date(strptime("2007-02-01", "%Y-%m-%d"))
dateRangeBelow <- convertedDate <= as.Date(strptime("2007-02-02", "%Y-%m-%d"))
dateRanges <- dateRangeBelow == TRUE & dateRangeAbove==TRUE
powerConsumptionFinal <- powerConsumptionCleansed[dateRanges,]
### Plot 2 ########
plot(powerConsumptionFinal$convertedDateTime,powerConsumptionFinal$Global_active_power, xlab="", ylab= "Global Active Power (kilowatts)", type= "l")
dev.copy(png, file="plot2.png")
dev.off()