Let say you have a dataframe containing mixed string and numeric columns. Since mean
is defined for numeric values, you need to first select numeric columns and then move forward with averaging. I don't have your dataframe, so I provide an example with another dataframe, but you can replace storms
with nitrates
.
library('dplyr')
data('storms')
# mean for each column
storms %>% select_if(is.numeric) %>% apply(2, mean, na.rm=T)
# mean for each row
storms %>% select_if(is.numeric) %>% apply(1, mean, na.rm=T)
# mean over all elements
storms %>% select_if(is.numeric) %>% as.matrix() %>% mean(na.rm=T)