forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun.R
More file actions
49 lines (34 loc) · 1.34 KB
/
Run.R
File metadata and controls
49 lines (34 loc) · 1.34 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#Exploratory Data Analysis - Project 1
#setwd("R:/Renne/Coursera/Data_Science/Exploratory Data Analysis/Project1/ExData_Plotting1")
library(ggplot2)
library(dplyr)
library(lubridate)
# Download and unzip data file
zip_file_name <- "power.zip"
if(!file.exists(zip_file_name)){
print("Downloading Zip Data...")
download.file("https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip", destfile = zip_file_name)
print("Unpacking Zip Data...")
unzip(zipfile = zip_file_name)
} else {
print("Data file already on disk, proceding...")
}
txt_file_name <- "household_power_consumption.txt"
# Check if data file exists
if(file.exists(txt_file_name)){
# Read data file
file <- read.csv(txt_file_name, sep = ";",header = TRUE, stringsAsFactors = FALSE, na.strings = c("?"))
power_data <- tbl_df(file)
power_data$Date_type <- as.Date(power_data$Date, format="%d/%m/%Y")
# Select only data between given dates
power_data <- filter(power_data, Date_type >= as.Date("2007-02-01") & Date_type <= as.Date("2007-02-02"))
dateTime <- paste(power_data$Date, power_data$Time, sep=' ')
power_data$Date_dateTime <- strptime(dateTime, format="%d/%m/%Y %H:%M:%S")
# Run all plots
source('plot1.R')
source('plot2.R')
source('plot3.R')
source('plot4.R')
} else {
printf("Text data file doesn't exists!")
}