# Calculate the Mean of each Row of an Object in R Programming – rowMeans() Function

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

 `# R program to illustrate  ` `# rowMean function ` `    `  `# Create example values ` `  `  `# Set seed ` `set``.seed(``1234``) ` `  `  ` ``# Create example data                                       ` `data <``-` `data.frame(matrix(``round``(runif(``12``, ``2``, ``20``)),      ` `                          ``nrow ``=` `4``, ncol ``=` `3``)) ` `  `  `# Print data ` `print``(rowMeans(data))                                       `

Output:

` 11.666667 12.666667  9.666667 10.333333`

Example 2:

 `# R program to illustrate  ` `# rowMean function ` `  `  `# Create example data with NA ` `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:

`  3 16  9  3`

My Personal Notes arrow_drop_up Check this out nerdboinet

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.