I would like to extract values falling within mean-1SD and mean+1SD, mean-2SD and mean+2SD from a data frame 'data' and in sum the values from extractions should be equal to the final sample size, but my following code do not give me correct values.
Any suggestions?
within1sd <- data[!(data$values < mean-SD & data$values > mean ), ]
within1sd <- data[!(data$values < mean-SD & data$values > mean ), ]
as @akrun says, you need to call/evaluate the mean
and sd
functions to get the mean and standard deviation, then you can use them to get the values you're after
something like:
mu <- mean(data$values)
sigma <- sd(data$values)
data[abs(data$values - mu) < sigma,]
you could of course put all this on one line, but thought this was easier to read
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.