I have a data frame with ~32k rows and 36 columns. I am trying to calculate the mean
of each row and creating a separate column
containing the mean
for each row. I originally calculated it for columns 19:33
via data$mean <- data[,19:33]
however now I want to exclude the highest and lowest values in each row to calculate the mean. Each row will have different high and low values in different locations. How can I effectively calculate the mean for each row while excluding those two values in each row?
2
votes
apply(X = data[,19:33], MARGIN = 1, function(x) mean(replace(x, c(which.min(x), which.max(x)), NA), na.rm = TRUE))
– d.b