R/SIX_FinalConversion.R

Defines functions FinalResultConvert

FinalResultConvert <- function(RESULT, ODClass, ODlevels,
  rownamesDataset, nrowsDataset, nr, nc, rowsNA, mi)
{
  RESULT <- apply(RESULT, 2, as.numeric)

  RESULT <- as.data.frame(RESULT)

    RESULT <- as.data.frame(
      sapply(RESULT, mapvalues,
      from = as.character(as.vector(1:length(ODlevels))),
      to = ODlevels, warn_missing = FALSE)
      )
    
    if (ODClass == "factor") {
      RESULT <- mutate_if(RESULT, is.character, as.factor)
    }



  #### We put again the rows having only NA's discarded at the beginning
  if (length(rowsNA) > 0) {
    for (i in 1:length(rowsNA)) {
      if (rowsNA[i] == 1) {
        RESULT <- rbind(rep(NA, ncol(RESULT)), RESULT)
      } else if (rowsNA[i] == nrowsDataset) {
        RESULT <- rbind(RESULT,rep(NA, ncol(RESULT)))
      } else {
        RESULT <- rbind(RESULT[1:(rowsNA[i] - 1), ],
                        rep(NA, ncol(RESULT)),
                        RESULT[rowsNA[i]:nrow(RESULT), ])
      }
    }
  }

  return(RESULT)
}

Try the seqimpute package in your browser

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

seqimpute documentation built on May 29, 2024, 4:35 a.m.