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).
6 Réponses
+ 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)
0
You calculate the values and then filter the mpg column by them
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 ?
0
thank you I get it
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))
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))