How to Calculate ZScore in R?
R doesn’t have an inbuilt function to calculate the zscore in R. To get the zscore in R, calculate the mean and standard deviation using the mean() and sd() functions in R and use mean and std. deviation values in the Zscore formula to find the zscore in R.
In this article, we will how to calculate the z score in R using the z score formula. We will calculate the mean and standard deviation for the vector using the r function and later calculate the z score.
What is a ZScore?
Zscore is the distance of the raw score value from the mean in terms of standard deviation. Raw scores above the mean have a positive Zscore value, while a raw score below the mean has a negative zscore value.
How to Calculate Zscore in R

Create the vector for the given data

Calculate the mean of the vector using the mean() function.

Calculate the standard deviation of the vector using the sd() function.

Calculate the zscore using the formula. zscore = data mean(data)) / sd(data)

The resultant vector will give the required zscore values.
Let’s understand how to find a zscore using R for a given vector using the stepbystep guide.
Calculate Zscore in R for the given vector
Let’s consider an example to get a zscore in R using the given vector data set.
Prepare vector in r to find the mean and standard deviation
 Create a vector for given data points and assign it to the data variable.
# create the vector for given data
data < c(19, 11, 12, 14, 15, 18, 19)
 Use the mean function to calculate the mean for a given vector.
# Calculate mean
mean(data)
 Use the standard deviation (sd) function to calculate the standard deviation for a given vector.
# Calculate standard deviation
sd(data)
 To calculate the zscore in r put the calculated mean and standard deviation in the z score formula, it will find the zscore and assign it to the zscore variable.
# calculate zscore
zscore < (data  mean(data)) / sd(data)
Use below R code to calculate the zscore.
ZScore in R code
# create the vector for given data
data < c(19, 11, 12, 14, 15, 18, 19)
# Calculate mean
mean(data)
# Calculate standard deviation
sd(data)
# calculate zscore
zscore < (data  mean(data)) / sd(data)
zscore
#Results
mean(data)
[1] 15.42857
>
> sd(data)
[1] 3.309438
> zscore
[1] 1.0791646 1.3381641 1.0359980 0.4316658
[5] 0.1294998 0.7769985 1.0791646
Interpretation of zscores in R

The zscore for data value 19 is 1.0791646. This means the raw score of 19 is 1.0791646 standard deviation above the mean of 15.42857.

The zscore for data value 11 is 1.3381641. This means the raw score of 11 is 1.3381641 standard deviation below the mean of 15.42857.

The zscore for data value 12 is 1.0359980. This means the raw score of 12 is 1.0359980 standard deviation below the mean of 15.42857.

The zscore for data value 14 is 0.4316658. This means the raw score of 14 is 0.4316658 standard deviation below the mean of 15.42857.
Cool Tip: Read more on how to Calculate Z Score in Excel!
Plot the Calculated Zscore for the given vector in R
# create the vector for given data
data < c(19, 11, 12, 14, 15, 18, 19)
# Calculate mean
mean(data)
# Calculate standard deviation
sd(data)
# calculate zscore
zscore < (data  mean(data)) / sd(data)
zscore
# plot zscore
plot(zscore, type="o", col="green")
The resultant plot for the calculated z score for the given data set is shown below.
Calculate Z score in R Calculate Z score in R
Conclusion
I hope the above article helps you to calculate the z score using r. We have learned how to prepare a vector for a given dataset and find the mean and standard deviation.
Using the zscore formula, we can find the zscore in r and plot the zscore on a chart.
You can find more topics about ZScore and how to calculate z score given the area on the ZscoreGeek home page.