rowMeans() function in R Language is used to find out the mean of each row of a data frame, matrix, or array.
Syntax: rowMeans(data)
Parameter:
data: data frame, array, or matrix
Example 1
set.seed(1234)
data <- data.frame(matrix(round(runif(12, 2, 20)),
nrow = 4, ncol = 3))
print(rowMeans(data))
|
Output:
[1] 11.666667 12.666667 9.666667 10.333333
Example 2:
data_na <- data.frame(matrix(round(runif(12, 2, 20)),
nrow = 4, ncol = 3))
data_na[rbinom(length(data_na), 1, 0.3) == 1] <- NA
data_na <- as.data.frame(data_na)
print(rowMeans(data_na, na.rm = TRUE))
|
Output:
[1] 3 16 9 3
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!