apply_reformat.Rd
Reformat values
apply_reformat(db, format = NULL)
(dm
) object input.
(list
) in a specific format.
a dm
object with re coded variables as factor. If not reformatted, original levels are preserved.
a dm
object with re coded variables as factor. If not re mapped, original levels are preserved.
Using the keyword All
as a table name will change the corresponding variable in every table where it appears.
library(dm)
#>
#> Attaching package: ‘dm’
#> The following object is masked from ‘package:stats’:
#>
#> filter
df1 <- data.frame(
"char" = c("a", "b", NA, "a", "k", "x"),
"fact" = factor(c("f1", "f2", NA, NA, "f1", "f1")),
"logi" = c(NA, FALSE, TRUE, NA, FALSE, NA)
)
df2 <- data.frame(
"char" = c("a", "b", NA, "a", "k", "x"),
"fact" = factor(c("f1", "f2", NA, NA, "f1", "f1"), levels = c("f1", "f2", "fx")),
"num" = 1:6
)
db <- dm(df1, df2)
new_formats <- list(
df1 = list(
char = list(
"A" = c("a", "k"),
"B" = "b"
)
),
df2 = list(
num = list(
"11" = "1",
"22" = "2"
)
),
ALL = list(
fact = list(
"F1" = "f1",
"F2" = "f2",
"FX" = "fx",
"<Missing>" = NA
),
other = list(
"x" = "X"
)
)
)
res <- apply_reformat(db, new_formats)