Last active
November 8, 2021 11:00
-
-
Save BroVic/eea59485c22ad62bc0deda79060578ca to your computer and use it in GitHub Desktop.
A modification of the builtin mtcars dataset that converts a couple of variables to factors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| stopifnot(getRversion() >= 4.1) | |
| dat <- mtcars | |
| levs <- | |
| structure( | |
| .Data = list(c("V-shaped", "straight"), c("automatic", "manual")), | |
| names = fcols <- c('vs', 'am') | |
| ) | |
| for (i in fcols) | |
| dat[[i]] <- (dat[[i]] == 0) |> | |
| ifelse(levs[[i]][1], levs[[i]][2]) |> | |
| as.factor() | |
| rm(levs, fcols, i) | |
| print(head(dat)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment