forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_script.R
More file actions
29 lines (18 loc) · 799 Bytes
/
Copy pathmain_script.R
File metadata and controls
29 lines (18 loc) · 799 Bytes
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
# Main Script that download and read file
# All the plot.R scripts depends on this script
# Project 1
# Coursera EDA class
# Code for reading data
fileUrl <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
fileZip <-"hpc"
if (!file.exists(fileZip)) download.file(fileUrl, fileZip, method = "auto")
# unzip the dataset into wd - dir 'UCI HAR Dataset'
if(file.exists(fileZip)){unzip(fileZip)}
# read data
hpc <- read.csv("household_power_consumption.txt", sep=";",stringsAsFactors = FALSE)
str(hpc)
# date conversion
d2 <- as.Date("2007-02-02", "%Y-%m-%d")
d1 <- as.Date("2007-02-01", "%Y-%m-%d")
s <- subset(hpc, as.Date(hpc$Date[1:nrow(hpc)], "%d/%m/%Y") >= d1 & as.Date(hpc$Date[1:nrow(hpc)], "%d/%m/%Y") <= d2)
s1 <- s # temp copy of data frame