From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

mean, rowMeans, and colMeans

mean, rowMeans, and colMeans

- [Instructor] During your research you're probably going to be generating a lot of averages and a lot of means, and there are a couple of commands you might want to know about. I've created a matrix, I've called it my matrix, let's take a quick look at it. My matrix is just simply a grid of numbers and they're random. Let's do a standard set of means across rows and columns. One way to do this is to use the apply command, it would look like this, apply, and I want to apply it against my matrix, here it is, I'm going to use one for the rows, and then I'm going to say I want to calculate a mean, and when I hit return, command+return, it calculates the mean of the rows, then I can get the mean of the columns by changing the margin parameter to two and I hit command+return and now I receive the mean of the columns, so we can go back to matrix and check and see yeah, three is probably the mean of the first column. Well, there are specific commands for this and not surprisingly one of them…

Contents