Advertisement
Guest User

12

a guest
Jan 26th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1.  
  2.  
  3. getwd()
  4. setwd("~/Desktop/CMPT318")
  5.  
  6. df <- read.table("Data_Assignment_1.txt",header = TRUE, sep = ",",dec = ".")
  7. library(EnvStats)
  8. library(modeest)
  9. class(df)
  10.  
  11.  
  12. # A: Global_active_power
  13. # B : Global_reactive_power
  14. # C: Voltage
  15. # D: Global_intensity
  16.  
  17.  
  18. vec_of_A <- c(df$Global_active_power)
  19.  
  20. mean_of_A <- mean(vec_of_A)
  21. median_of_A <- median(vec_of_A)
  22. mode_of_A <- mfv(vec_of_A)
  23. sd_of_A <- sd(vec_of_A)
  24. geomean_of_A <- geoMean( vec_of_A [vec_of_A >0])
  25.  
  26.  
  27.  
  28.  
  29. vec_of_B <- c(df$Global_reactive_power)
  30.  
  31. geomean_of_B <- geoMean( vec_of_B[vec_of_B >0])
  32. mean_of_B <- mean(vec_of_B , use = "complete.obs")
  33. median_of_B <- median(vec_of_B)
  34. mode_of_B <- mfv(vec_of_B)
  35. sd_of_B <- sd(vec_of_B)
  36.  
  37. vec_of_C <-c(df$Voltage)
  38. vec_of_D <-c(df$Global_intensity)
  39.  
  40.  
  41. print(geomean_of_A)
  42. print(geomean_of_B)
  43. print(mean_of_A)
  44. print(mean_of_B)
  45. print(median_of_A)
  46. print(median_of_B)
  47. print(mode_of_A)
  48. print(mode_of_B)
  49. print(sd_of_A)
  50. print(sd_of_B)
  51.  
  52.  
  53. df$Date <- as.POSIXlt(df$Date ,format = "%d/%m/%Y")
  54. df$Time <- strptime(df$Time,format = "%H:%M:%S")
  55.  
  56.  
  57. 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",]
  58. weekends_df <- df[df$Date == "2007-04-07" | df$Date == "2007-04-08",]
  59.  
  60.  
  61. library(lubridate)
  62. day_weekdays_df <-weekdays_df[ hour(weekdays_df$Time) >= 6 & hour(weekdays_df$Time) <18 ,]
  63. night_weekdays_df <- weekdays_df[ hour(weekdays_df$Time) >= 18 | hour(weekdays_df$Time) <6 ,]
  64.  
  65. day_weekends_df <-weekends_df[ hour(weekends_df$Time) >= 6 & hour(weekends_df$Time) <18 ,]
  66. night_weekends_df <- weekends_df[ hour(weekends_df$Time) >= 18 | hour(weekends_df$Time) <6 ,]
  67.  
  68. #A Global_active_power
  69. print(max(day_weekdays_df$Global_active_power))
  70. print(min(day_weekdays_df$Global_active_power))
  71. print(max(night_weekdays_df$Global_active_power))
  72. print(min(night_weekdays_df$Global_active_power))
  73. print(max(day_weekends_df$Global_active_power))
  74. print(min(day_weekends_df$Global_active_power))
  75. print(max(night_weekends_df$Global_active_power))
  76. print(min(night_weekends_df$Global_active_power))
  77.  
  78.  
  79.  
  80. #B global_reactive_power
  81.  
  82. print(max(day_weekdays_df$Global_reactive_power))
  83. print(min(day_weekdays_df$Global_reactive_power))
  84. print(max(night_weekdays_df$Global_reactive_power))
  85. print(min(night_weekdays_df$Global_reactive_power))
  86. print(max(day_weekends_df$Global_reactive_power))
  87. print(min(day_weekends_df$Global_reactive_power))
  88. print(max(night_weekends_df$Global_reactive_power))
  89. print(min(night_weekends_df$Global_reactive_power))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement