# apartado 1
ambos_na <- function(x, y) {
sum(is.na(x) & is.na(y))
}
# apartado 2
ambos_na <- function(x, y) {
if (length(x) != length(y)) {
return(NA)
}
sum(is.na(x) & is.na(y))
}
library(dplyr)
types <- character(ncol(starwars))
for(i in seq_along(starwars)) {
types[[i]] <- typeof(starwars[[i]])
}
library(dplyr)
library(purrr)
types <- character(ncol(starwars))
for(i in seq_along(starwars)) {
types[[i]] <- typeof(starwars[[i]])
}
# apartado 1
map_chr(starwars, typeof)
# apartado 2
fn <- ~list(n_distinct = n_distinct(.), class = class(.))
# apartado 3
map_dfr(starwars, fn)
# apartado 4
map_dfr(starwars, fn, .id = "variable")
# apartado 5
fn <- ~sum(is.na(.))
# apartado 6
escalar_max_min <- function(x) {
(x - min(x)) / (max(x) - min(x))
}