Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 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], na.rm= TRUE)
  32. mean_of_B <- mean(vec_of_B, na.rm= TRUE )
  33. median_of_B <- median(vec_of_B, na.rm= TRUE)
  34. mode_of_B <- mfv(vec_of_B, na_rm= TRUE)
  35. sd_of_B <- sd(vec_of_B, na.rm= TRUE)
  36.  
  37. vec_of_C <-c(df$Voltage)
  38. vec_of_D <-c(df$Global_intensity)
  39.  
  40.  
  41. corelation_of_AB<- (cor(vec_of_A, vec_of_B, use = "complete.obs", method = "pearson"))
  42.  
  43.  
  44. corelation_of_AC<- (cor(vec_of_A, vec_of_C, use = "complete.obs", method = "pearson"))
  45.  
  46.  
  47. corelation_of_AD<- (cor(vec_of_A, vec_of_D, use = "complete.obs", method = "pearson"))
  48. corelation_of_BC<- (cor(vec_of_B, vec_of_C, use = "complete.obs", method = "pearson"))
  49. corelation_of_BD<- (cor(vec_of_B, vec_of_D, use = "complete.obs", method = "pearson"))
  50. corelation_of_CD<- (cor(vec_of_C, vec_of_D, use = "complete.obs", method = "pearson"))
  51.  
  52. print(geomean_of_A)
  53. print(geomean_of_B)
  54. print(mean_of_A)
  55. print(mean_of_B)
  56. print(median_of_A)
  57. print(median_of_B)
  58. print(mode_of_A)
  59. print(mode_of_B)
  60. print(sd_of_A)
  61. print(sd_of_B)
  62. print(corelation_of_AB)
  63. print(corelation_of_AC)
  64. print(corelation_of_AD)
  65. print(corelation_of_BC)
  66. print(corelation_of_BD)
  67. print(corelation_of_CD)
  68.  
  69. df$Date <- as.POSIXlt(df$Date ,format = "%d/%m/%Y")
  70. df$Time <- strptime(df$Time,format = "%H:%M:%S")
  71.  
  72.  
  73. 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",]
  74. weekends_df <- df[df$Date == "2007-04-07" | df$Date == "2007-04-08",]
  75.  
  76.  
  77. library(lubridate)
  78. day_weekdays_df <-weekdays_df[ hour(weekdays_df$Time) >= 6 & hour(weekdays_df$Time) <18 ,]
  79. night_weekdays_df <- weekdays_df[ hour(weekdays_df$Time) >= 18 | hour(weekdays_df$Time) <6 ,]
  80.  
  81. day_weekends_df <-weekends_df[ hour(weekends_df$Time) >= 6 & hour(weekends_df$Time) <18 ,]
  82. night_weekends_df <- weekends_df[ hour(weekends_df$Time) >= 18 | hour(weekends_df$Time) <6 ,]
  83.  
  84. #A Global_active_power
  85. print(max(day_weekdays_df$Global_active_power))
  86. print(min(day_weekdays_df$Global_active_power))
  87. print(max(night_weekdays_df$Global_active_power))
  88. print(min(night_weekdays_df$Global_active_power))
  89. print(max(day_weekends_df$Global_active_power))
  90. print(min(day_weekends_df$Global_active_power))
  91. print(max(night_weekends_df$Global_active_power))
  92. print(min(night_weekends_df$Global_active_power))
  93.  
  94.  
  95.  
  96. #B global_reactive_power
  97.  
  98. print(max(day_weekdays_df$Global_reactive_power))
  99. print(min(day_weekdays_df$Global_reactive_power))
  100. print(max(night_weekdays_df$Global_reactive_power))
  101. print(min(night_weekdays_df$Global_reactive_power))
  102. print(max(day_weekends_df$Global_reactive_power))
  103. print(min(day_weekends_df$Global_reactive_power))
  104. print(max(night_weekends_df$Global_reactive_power))
  105. print(min(night_weekends_df$Global_reactive_power))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement