Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getwd()
- setwd("~/Desktop/CMPT318")
- df <- read.table("Data_Assignment_1.txt",header = TRUE, sep = ",",dec = ".")
- library(EnvStats)
- library(modeest)
- class(df)
- # A: Global_active_power
- # B : Global_reactive_power
- # C: Voltage
- # D: Global_intensity
- vec_of_A <- c(df$Global_active_power)
- mean_of_A <- mean(vec_of_A)
- median_of_A <- median(vec_of_A)
- mode_of_A <- mfv(vec_of_A)
- sd_of_A <- sd(vec_of_A)
- geomean_of_A <- geoMean( vec_of_A [vec_of_A >0])
- vec_of_B <- c(df$Global_reactive_power)
- geomean_of_B <- geoMean( vec_of_B[vec_of_B >0])
- mean_of_B <- mean(vec_of_B , use = "complete.obs")
- median_of_B <- median(vec_of_B)
- mode_of_B <- mfv(vec_of_B)
- sd_of_B <- sd(vec_of_B)
- vec_of_C <-c(df$Voltage)
- vec_of_D <-c(df$Global_intensity)
- print(geomean_of_A)
- print(geomean_of_B)
- print(mean_of_A)
- print(mean_of_B)
- print(median_of_A)
- print(median_of_B)
- print(mode_of_A)
- print(mode_of_B)
- print(sd_of_A)
- print(sd_of_B)
- df$Date <- as.POSIXlt(df$Date ,format = "%d/%m/%Y")
- df$Time <- strptime(df$Time,format = "%H:%M:%S")
- weekdays_df <- df[df$Date == "2007-04-02" | df$Date =="2007-04-03" |df$Date == "2007-04-04"| df$Date == "2007-04-05"|df$Date == "2007-12-06",]
- weekends_df <- df[df$Date == "2007-04-07" | df$Date == "2007-04-08",]
- library(lubridate)
- day_weekdays_df <-weekdays_df[ hour(weekdays_df$Time) >= 6 & hour(weekdays_df$Time) <18 ,]
- night_weekdays_df <- weekdays_df[ hour(weekdays_df$Time) >= 18 | hour(weekdays_df$Time) <6 ,]
- day_weekends_df <-weekends_df[ hour(weekends_df$Time) >= 6 & hour(weekends_df$Time) <18 ,]
- night_weekends_df <- weekends_df[ hour(weekends_df$Time) >= 18 | hour(weekends_df$Time) <6 ,]
- #A Global_active_power
- print(max(day_weekdays_df$Global_active_power))
- print(min(day_weekdays_df$Global_active_power))
- print(max(night_weekdays_df$Global_active_power))
- print(min(night_weekdays_df$Global_active_power))
- print(max(day_weekends_df$Global_active_power))
- print(min(day_weekends_df$Global_active_power))
- print(max(night_weekends_df$Global_active_power))
- print(min(night_weekends_df$Global_active_power))
- #B global_reactive_power
- print(max(day_weekdays_df$Global_reactive_power))
- print(min(day_weekdays_df$Global_reactive_power))
- print(max(night_weekdays_df$Global_reactive_power))
- print(min(night_weekdays_df$Global_reactive_power))
- print(max(day_weekends_df$Global_reactive_power))
- print(min(day_weekends_df$Global_reactive_power))
- print(max(night_weekends_df$Global_reactive_power))
- print(min(night_weekends_df$Global_reactive_power))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement