# NOT RUN {
dat <- data.frame(c1 = c(1,2,NA,4),
c2 = c(NA,2,NA,5),
c3 = c(NA,4,NA,NA),
c4 = c(2,3,7,8))
# needs at least 4 non-missing values per row
mean_n(dat, 4) # 1 valid return value
# needs at least 3 non-missing values per row
mean_n(dat, 3) # 2 valid return values
# needs at least 2 non-missing values per row
mean_n(dat, 2)
# needs at least 1 non-missing value per row
mean_n(dat, 1) # all means are shown
# needs at least 50% of non-missing values per row
mean_n(dat, .5) # 3 valid return values
# needs at least 75% of non-missing values per row
mean_n(dat, .75) # 2 valid return values
# }
Run the code above in your browser using DataLab