How to Calculate Average in R
In R language, you can use the function mean() to calculate the average of a set of data. For example, for a vector containing multiple values, you can use the following code to calculate its average:
# 创建一个包含多个数值的向量
x <- c(1, 2, 3, 4, 5)
# 计算向量x的平均值
average <- mean(x)
# 输出平均值
print(average)
The code above calculates the average of vector x and outputs the result. The mean() function makes it easy to calculate the average of a dataset.