#' Specify the response and predictors (if any) from dataframe.
#'
#' @param x A data frame
#' @param response Character. One column which will be chosen as response
#' @param explanatory Character. The columns to be the explanatory variables
#'
#' @return Dataframe containing one column for response variable and zero or more columns for the explanatory variables. The first column is always the response.
#' @export
#'
#' @examples
#' # select Sepal.Length data from data frame `iris`
#' specify(iris,"Sepal.Length")
specify <- function(x,response,explanatory=NULL){
if (!is.data.frame(x)){
stop("TypeError: Input should be a data frame")
}
if (is.null(response)==TRUE){
stop("TypeError: Response missing")
}
if (is.character(response)==FALSE){
stop("TypeError: Response should be of type character")
}
col <- c(response)
# if explantory value added
if (is.null(explanatory)==FALSE){
if (is.character(explanatory)==FALSE){
stop("TypeError: Explantory should be of type character")
}
col <- append(response,explanatory)
}
df_output <- x[col]
df_output
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.