简体   繁体   中英

How do i find the standard deviation score for all values in R?

For example i have a mean based on function mean(value)= 1.278394 and i have a standard deviation for the values at.8028161

I would basically like the dataset to look like this

  value| sd score
1.278394       0
2.0812101      1
.4755779      -1
2.8840262      2
1.67980205   0.5

I guess you can call this sd score?

"z score" is the common term for the number of standard deviations from the mean. You can calculate this easily for a vector, either manually or with the scale function:

my_mean = 1.278394 
my_sd = .8028161
x = rnorm(10, my_mean, my_sd)
z_score = (x - my_mean) / my_sd

# the scale function does this for you
scale(x, my_mean, my_sd) 

If you don't supply the mean and sd, scale will calculate it based on the x values. So in your data frame you can do something like:

my_data$z_score = scale(my_data$value)

and the scale defaults will do what you want.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM