forked from jlprog/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot1.R
21 lines (17 loc) · 754 Bytes
/
plot1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#Data file must be saved in the working directory
if( !file.exists("household_power_consumption.txt"))
{
print("Data file household_power_consumption.txt does not exist")
return
}
#Read data on 2007-02-01 and 2007-02-02 from text file household_power_consumption.txt
library(data.table)
fileName <- "household_power_consumption.txt"
dtime <- difftime(as.POSIXct("2007-02-03"), as.POSIXct("2007-02-01"),units="mins")
rowsToRead <- as.numeric(dtime)
DT <- fread( fileName, skip="1/2/2007", nrows = rowsToRead, na.strings = c("?", ""))
setnames(DT, colnames(fread(fileName, nrows=0)))
png(filename="plot1.png")
hist(DT$Global_active_power,col=2,main="Global Active Power",xlab="Global Active Power (kilowatts)")
dev.off()
rm(list=ls())