0
my_df <- tibble(
  b1 = c(2, 6, 3, 6, 4, 2, 1, 9, NA), 
  b2 = c(NA, 4, 6, 2, 6, 6, 1, 1, 7), 
  b3 = c(5, 9, 8, NA, 2, 3, 9, 5, NA), 
  b4 = c(NA, 6, NA, 10, 12, 8, 3, 6, 2),
  b5 = c(2, 12, 1, 7, 8, 5, 5, 6, NA),
  b6 = c(9, 2, 4, 6, 7, 6, 6, 7, 9),
  b7 = c(1, 3, 7, 7, 4, 2, 2, 9, 5),
  b8 = c(NA, 8, 4, 5, 1, 4, 1, 3, 6),
  b9 = c(4, 5, 7, 9, 5, 1, 1, 2, NA),
  b10 = c(14, 2, 4, 2, 1, 1, 1, 1, 5))

Hello,

I have a df like this. And I want to use rowmeans to get the mean of b1,b2,b4 and b5. In instances where there are any missing values, I will like R to calculate mean using the remaining values. Any help will be appreciated. Thanks

lofus77
  • 181
  • 5

0 Answers0