-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.r
executable file
·25 lines (23 loc) · 927 Bytes
/
1.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
25
if (!file.exists("data/household_power_consumption.txt")){
dir.create("data")
temp <- tempfile()
fileUrl<-"http://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(fileUrl,temp)
unzip(temp,exdir="./data" )
}
data<-read.table("./data/household_power_consumption.txt", colClasses = "character", sep=";", header=TRUE)
data$Date<-as.Date(data$Date,"%d/%m/%Y")
date1<-as.Date("2007-02-01")
date2<-as.Date("2007-02-02")
out<-data[(data$Date>=date1 & data$Date<=date2),]
Sys.setlocale('LC_TIME', 'C')
colnames1<-colnames(out)
dates<-out$Date
times<-out$Time
x <- paste(dates, times)
out<-cbind(out, strptime(x, "%Y-%m-%d %H:%M:%S") )
colnames(out)<-c(colnames1,"DT")
par(mfrow=c(1,1))
hist(as.numeric(out$Global_active_power), col="red", xlab = "Global Active Power (kilowatts)", main=" Global Active Power" )
dev.copy(png, file="1.png")
dev.off()