Untitled

 avatar
unknown
plain_text
a year ago
803 B
4
Indexable
#computing the arithmetic and geometric mean, median, mode, and sd for feature A. 
#Deal with any missing values as well/
arith_meanA<-mean(my_data$Global_active_power, na.rm = TRUE)
#compute geometric mean for feature A.
geo_meanA<-exp(mean(log(my_data$Global_active_power), na.rm = TRUE))
#compute median for feature A.
medianA<-median(my_data$Global_active_power, na.rm = TRUE)
#compute mode for feature A.
mode<-function(x){
  unix <-unique(x)
  unix[which.max(tabulate(match(x,unix)))]
}
modeA<-mode(my_data$Global_active_power)

#standard deviation computation
sdA<-sd(my_data$Global_active_power, na.rm = TRUE)

print(paste("Computations for feature A: ", "Arithmetic Mean:", arith_meanA, 
            "Geometric Mean:", geo_meanA, "Median:", medianA, "Mode:", modeA, "Standard Deviation:", sdA))
Editor is loading...