Calculate mean for only three values per row

user4110499

I have a matrix like this:

mt1=matrix(1:144,ncol=12,nrow=12)

And I would like only to calcutate the mean only for 3 values in a row. These are the three first values:

   [,1] [,2] [,3] 
[1,]  1   13   25

the mean should be 13.

And the same for the next three values and the same for the next three values.. And so on and on until the end of rows.

I know I have to use the apply function, but I cannot figure out to apply the mean only to specific values that is only to a sequence of rows, and then on the next sequence of rows, and get then as a result a vector with the means of only 3 values per row.

Thanks a lot!

rnso

Try:

> apply(mm, 1, function(x) mean(x[1:3]))
[1] 13 14 15 16 17 18 19 20 21 22 23 24

Mean of 1,13,25 is not 29 but 13

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calculate mean difference per row and per group

From Dev

How to calculate mean of values per unique class

From Dev

How to calculate mean of every three values of a list

From Dev

Calculate mean for each row containing lists of values

From Dev

In R, how to calculate mean per column and row respectively?

From Dev

Pandas groupby and append the original values. Count the mean of per row

From Dev

Calculate the sum of column values per row but not include every value

From Dev

Getting the three smallest values per row and returning the correspondent column names

From Dev

R - How to find three smallest values per row in a data frame?

From Dev

Calculate mean of row using only certain columns in pandas

From Dev

How to calculate Mean of specific values in each row of a data frame?

From Dev

Calculate the mean of several values within the same row in a column

From Dev

How to calculate mean values per values in other column in one PROC SQL query in SAS Enterprise Guide?

From Dev

Calculate mean of calculated values

From Dev

Calculate mean difference values

From Dev

Calculate the mean of values in a loop

From Dev

Compare values per row

From Dev

CSS - Three containers per row

From Dev

R: calculate the row mean in a matrix

From Dev

Calculate row mean with condition in dplyr

From Dev

Calculate mean of specific row pattern

From Dev

Calculate Mean for each CSV row

From Javascript

Calculate mean max value per timeframe of array

From Dev

Calculate mean per few columns in Pandas Dataframe

From Dev

Calculate new values by row

From Dev

Calculate the mean values if the numbers are same

From Dev

DAX Calculate Distinct Count only for values in both Table A and B per User

From Dev

calculate mean only when the number of values in each rows is higher then certain number in python pandas

From Dev

How calculate the mean by ID when there is more than one individual and the median when there is only one for missing values in R?

Related Related

  1. 1

    Calculate mean difference per row and per group

  2. 2

    How to calculate mean of values per unique class

  3. 3

    How to calculate mean of every three values of a list

  4. 4

    Calculate mean for each row containing lists of values

  5. 5

    In R, how to calculate mean per column and row respectively?

  6. 6

    Pandas groupby and append the original values. Count the mean of per row

  7. 7

    Calculate the sum of column values per row but not include every value

  8. 8

    Getting the three smallest values per row and returning the correspondent column names

  9. 9

    R - How to find three smallest values per row in a data frame?

  10. 10

    Calculate mean of row using only certain columns in pandas

  11. 11

    How to calculate Mean of specific values in each row of a data frame?

  12. 12

    Calculate the mean of several values within the same row in a column

  13. 13

    How to calculate mean values per values in other column in one PROC SQL query in SAS Enterprise Guide?

  14. 14

    Calculate mean of calculated values

  15. 15

    Calculate mean difference values

  16. 16

    Calculate the mean of values in a loop

  17. 17

    Compare values per row

  18. 18

    CSS - Three containers per row

  19. 19

    R: calculate the row mean in a matrix

  20. 20

    Calculate row mean with condition in dplyr

  21. 21

    Calculate mean of specific row pattern

  22. 22

    Calculate Mean for each CSV row

  23. 23

    Calculate mean max value per timeframe of array

  24. 24

    Calculate mean per few columns in Pandas Dataframe

  25. 25

    Calculate new values by row

  26. 26

    Calculate the mean values if the numbers are same

  27. 27

    DAX Calculate Distinct Count only for values in both Table A and B per User

  28. 28

    calculate mean only when the number of values in each rows is higher then certain number in python pandas

  29. 29

    How calculate the mean by ID when there is more than one individual and the median when there is only one for missing values in R?

HotTag

Archive