In R, you can use the mean()
function to calculate the mean of a numerical vector, and the sd()
function to calculate the standard deviation of a numerical vector. Here is an example:
# Create a numerical vector
x <- c(1, 2, 3, 4, 5)
# Calculate the mean
mean(x)
# Calculate the standard deviation
sd(x)
You can also use the summary()
function to get the mean and standard deviation together with other summary statistics of a numerical vector.
There is also a package called psych
which has more advanced functionality for calculating descriptive statistics, like describe()
function which gives a more detailed summary of the data.
library(psych)
describe(x)
You can install the package by using install.packages("psych")
and load the package by using library(psych)
.