Path: blob/main/Trabajo_grupal/WG3/Solucion/script_r.R
2835 views
################ WG3 R script ############################1## Curso: Laboratorio de R y Python ###########################2## @author: Roberto Mendoza345# Loop replacement a un vector67vector = sample(1:500, size = 100)8910escalar <- function (x, min_x, max_x){ (x - min_x)/(max_x - min_x) }111213lapply(vector, escalar, min_x = min(vector), max_x = max(vector))141516sapply(vector, escalar, min_x = min(vector), max_x = max(vector) )17181920# Loop replacement a una matrix2122elements <- sample(5000) # random number2324M <- matrix(elements , nrow = 100, ncol = 50) # reshape matrix252627escalar <- function(x){ (x-min(x))/(max(x) - min(x)) }282930apply(M, 2, escalar) # 2 para que aplicase la función por columnas31323334353637383940414243444546474849505152535455565758596061626364