R/makeNumCols.R

Defines functions makeCharCols makeNumCols

Documented in makeNumCols

# makeNumCols and makeCharCols
#' These are internal functions that eliminate factors
#'
#' It returns a data.frame
#'
#' @keywords internal
#'
#' @param df data.frame
#'
#' @return data.frame
#'
makeNumCols <- function(df) {
  df <- as.data.frame(df)
  if (nrow(df) > 0) {
    df[] <- lapply(df, as.character)
    cond <- apply(df, 2, function(x) {
      x <- x[!is.na(x)]
      all(suppressWarnings(!is.na(as.numeric(x))))
    })
    numeric_cols <- names(df)[cond]
    df[, numeric_cols] <- sapply(df[, numeric_cols], as.numeric)
    return(df)
  }
}

makeCharCols <- function(df) {
  df <- as.data.frame(df)
  df[] <- lapply(df, as.character)
  return(df)
}

Try the idiogramFISH package in your browser

Any scripts or data that you put into this service are public.

idiogramFISH documentation built on Aug. 22, 2023, 5:08 p.m.