Skip to content

Instantly share code, notes, and snippets.

@mribeirodantas
Created March 3, 2020 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mribeirodantas/2fcaeb5f8e2b692ef5e38053ef658bea to your computer and use it in GitHub Desktop.
Save mribeirodantas/2fcaeb5f8e2b692ef5e38053ef658bea to your computer and use it in GitHub Desktop.
# Your new preprocess.R should look like this
input_file <- read.csv(file = 'data/simulation.tsv',
sep='\t',
stringsAsFactors=FALSE)
input_file <- input_file[, 1:50]
input_file <- lapply(input_file,
function(x) replace(x,
is.na(x),
mean(x,
na.rm = TRUE)))
input_file <- as.data.frame(input_file)
input_file[, unlist(lapply(input_file, is.numeric))] <-
apply(input_file[, unlist(lapply(input_file, is.numeric))],
2,
function(x) ifelse(x < 0, -1, x))
input_file[, unlist(lapply(input_file, is.numeric))] <-
apply(input_file[, unlist(lapply(input_file, is.numeric))],
2,
function(x) ifelse(x > 0, 1, x))
write.csv2(input_file,
'data/simulation_preprocessed.csv',
row.names=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment