0

SD FOR MEAN !!!

help how can I solve this ? We are working with the mtcars dataset and need to find the number of cars that fall into 1 standard deviation from the mean of the mpg column. This means that we need to find the cars that have the mpg value in the range of mean(mpg)-sd(mpg) and mean(mpg)+sd(mpg).

26th Jan 2022, 6:22 PM
yasmine saoud
6 ответов
+ 2
# note the , ! x is a dataframe, not a vector! x<- mtcars[mtcars$mpg<a &mtcars$mpg>b,] # a x is a dataframe, you need to determine the number of rows, not the length nrow(x)
26th Jan 2022, 6:49 PM
Lisa
Lisa - avatar
0
You calculate the values and then filter the mpg column by them
26th Jan 2022, 6:33 PM
Lisa
Lisa - avatar
0
a<-mean(mtcars$mpg)+sd(mtcars$mpg) b<-mean(mtcars$mpg)-sd(mtcars$mpg) x<- mtcars[mtcars$mpg<a &mtcars$mpg>b] length(x) why is this wrong please ?
26th Jan 2022, 6:41 PM
yasmine saoud
0
thank you I get it
26th Jan 2022, 7:06 PM
yasmine saoud
0
x <- (mtcars$mpg) a<-mean(mtcars$mpg)-sd(mtcars$mpg) b<-mean(mtcars$mpg)+sd(mtcars$mpg) tar <- mtcars[mtcars$mpg>a & mtcars$mpg<b,] print(nrow(tar))
11th Feb 2022, 12:42 PM
Mohab Ashraf Rady
0
mean1 <- mean(mtcars$mpg) sd1 <- sd(mtcars$mpg) lowr <- mean1 - sd1 uppr <- mean1 + sd1 in_range <- subset(mtcars, mpg >= lowr & mpg <= uppr, select= c(mpg)) print(length(in_range$mpg))
4th Apr 2023, 6:36 AM
Grace Johnruz Imperial