In: Statistics and Probability
In R, compute the mean and standard deviation for at least three numerical data columns. You will need to use read.csv to read your data file into an R data frame. Post your code on GitHub, and post the means and standard deviations on your webpage.
SOl:
url <-
"http://rstatistics.net/wp-content/uploads/2015/09/ozone.csv"
ozonedt <- read.csv(url)
dim(ozonedt)
names(ozonedt)
there were 366 rows and 13 columns.
column names are:
[1] "Month" "Day_of_month" "Day_of_week" "ozone_reading"
[5] "pressure_height" "Wind_speed" "Humidity"
"Temperature_Sandburg"
[9] "Temperature_ElMonte" "Inversion_base_height"
"Pressure_gradient" "Inversion_temperature"
[13] "Visibility"
To get mean and standard deviation for at least three numerical data columns
Rcode is
mean(ozonedt$Wind_speed,na.rm=TRUE)
mean(ozonedt$Humidity,na.rm=TRUE)
mean(ozonedt$Temperature_Sandburg,na.rm=TRUE)
sd(ozonedt$Wind_speed,na.rm=TRUE)
sd(ozonedt$Humidity,na.rm=TRUE)
sd(ozonedt$Temperature_Sandburg,na.rm=TRUE)
OUTPUT IS:
> dim(ozonedt)
[1] 366 13
> names(ozonedt)
[1] "Month" "Day_of_month" "Day_of_week" "ozone_reading"
[5] "pressure_height" "Wind_speed" "Humidity"
"Temperature_Sandburg"
[9] "Temperature_ElMonte" "Inversion_base_height"
"Pressure_gradient" "Inversion_temperature"
[13] "Visibility"
> head(ozonedt)
Month Day_of_month Day_of_week ozone_reading pressure_height
Wind_speed Humidity
1 1 1 4 3.01 5480 8 20
2 1 2 5 3.20 5660 6 NA
3 1 3 6 2.70 5710 4 28
4 1 4 7 5.18 5700 3 37
5 1 5 1 5.34 5760 3 51
6 1 6 2 5.77 5720 4 69
Temperature_Sandburg Temperature_ElMonte Inversion_base_height
Pressure_gradient
1 NA NA 5000 -15
2 38 NA NA -14
3 40 NA 2693 -25
4 45 NA 590 -24
5 54 45.32 1450 25
6 35 49.64 1568 15
Inversion_temperature Visibility
1 30.56 200
2 NA 300
3 47.66 250
4 55.04 100
5 57.02 60
6 53.78 60
> mean(ozonedt$ozone_reading,na.rm=TRUE)
[1] 11.51934
> mean(ozonedt$Wind_speed,na.rm=TRUE)
[1] 4.868852
> mean(ozonedt$Humidity,na.rm=TRUE)
[1] 58.47578
> mean(ozonedt$Temperature_Sandburg,na.rm=TRUE)
[1] 61.91484
> sd(ozonedt$Wind_speed,na.rm=TRUE)
[1] 2.116928
> sd(ozonedt$Humidity,na.rm=TRUE)
[1] 19.75923
> sd(ozonedt$Temperature_Sandburg,na.rm=TRUE)
[1] 14.27653