.onAttach <- function(libname, pkgname) {
packageStartupMessage("Welcome to my first R-package and thanks for using it, muchacho!")
}
#' Calculates the difference of the height to the mean.
#'
#' @description Takes a set of students and calculates the (sex-specific) mean
#' of this group. Returns the set of students and th difference to the group
#' average height.
#' @param students.input A data.frame with at least 'name' and 'height'
#' @param sex.specific Use sex specific averages
#' @param print.statement Indicator whether a notification message should be
#' printed after calculation is completed successfully
#' @return data.frame with the names and difference in meter
#' @examples load(file = "./data/example.rda")
#' checkHeight(students.csv)
#' @export
checkHeight <- function(students.input, sex.specific = TRUE, print.statement = FALSE) {
# assert_data_frame(students.input, min.rows=4, ncols=5,
# types=c("numeric", "numeric", "numeric", "factor", "character"))
# assert_numeric(students.input[,3], lower=1.30, upper=2.40)
# assert_factor(students.input[,4], levels=c("F", "M"))
# assert_logical(sex.specific, len=1)
# assert_logical(print.statement, len=1)
heights <- apply(students.input, 1, function(stud) {
if (!sex.specific) {
avg <- mean(students.input$height)
} else {
if(stud["sex"] == "M")
avg <- mean(students.input[students.input["sex"]=="M",]$height)
else
avg <- mean(students.input[students.input["sex"]=="F",]$height)
}
avg - as.numeric(stud["height"])
})
if(print.statement)
print("Yippie, I calculated the mean differences!")
return(data.frame(name = students.input$name, height = heights))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.