Error message from setData

Tried to run the example from here: RPubs - Artificial Neural Networks in R
but got error message: could not find function "setData"

Here is the code:
dt <- setData(Boston, "medv")

How to fix the issue?

The autor doesn't make it clear but that is a user defined function, it is not part of the MASS package. If you look into the referenced github repository you can find how the function is defined

setData <- function(df, resp, makeFactorResp = FALSE) {
  if (makeFactorResp) { # if resp should be a factor but is not one
    df[[resp]] <- factor(df[[resp]])
    isFactorResp <- TRUE
  num_classes <- NA
  if (any(class(df[[resp]]) == "factor")) {
    num_classes <- length(levels(factor(df[[resp]])))
  respCol = getRespCol(df, resp)
  ptype <- if (is.numeric(df[[resp]])) { "regression" } else { "classification"}
  df.e <- list(dt.frm = df
              , resp = resp
              , num_classes = num_classes
              , vars = names(df)[-respCol]
              , vars_fac = sapply(df[-respCol], function(j) { any(class(j) == "factor") } )
              , respCol = respCol
              , ptype = ptype
  class(df.e) <- "df.enum"

The code in this article is not reproducible so you shouldn't take it as a step by step guide.

1 Like

Thank you so much!!!!!!!!!!!!!!!!!!!!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.