Is there a command on "R" to find the z score for variables in preloaded datasets within "R'.

I'm working on an assignment for school using "R" for the first time. We are using a dataset that was preloaded on "R" referred to as "mtcars". I've already found the mean, and standard deviation for several variables, but now I need to calculate the Z score for them. Is there a command to use in "R" to calculate z scores?

data <- mtcars
m <- mean(data$mpg)
s <- sd(data$mpg)
z <- (data$mpg - m)/s
z

Not sure if I am entering this solution wrong, but I cant get this to work

My output looks like this for z values of the mpg column:
[1] 0.15088482 0.15088482 0.44954345 0.21725341 -0.23073453 -0.33028740
[7] -0.96078893 0.71501778 0.44954345 -0.14777380 -0.38006384 -0.61235388
[13] -0.46302456 -0.81145962 -1.60788262 -1.60788262 -0.89442035 2.04238943
[19] 1.71054652 2.29127162 0.23384555 -0.76168319 -0.81145962 -1.12671039
[25] -0.14777380 1.19619000 0.98049211 1.71054652 -0.71190675 -0.06481307
[31] -0.84464392 0.21725341

Show us the commands you used and the resulting output.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.