I have a data frame with blanks at different positions. I would like to calculate a mean of the rows but I do not know how to make the n flexible depending on the row.
All the columns have the same amount of rows.
mean = sum/n
df1 <- data.frame(col1 = c(5, 9, NA, -0.9, -0.74, , 1.19, , -1, -0.4, 1.38, -1.5, 1, 0.64),
col2 = c(4, 2, -9, 4, 19, 31, 4, -8, -15,NA,NA,NA,NA,NA),
col3 = c(1, -2, 5, 1.1, 33, 2, 7, 1, 1, 16, -22, - 2, -3,-10))
So that, for row1:
5+4+1 = 9/3 = 3
but for row 3: (-9) + 5 = -4/2 = -2
Thank you very much for your help!