# NOT RUN {
## initialize lama_dictinoary
dict <- new_lama_dictionary(
subject = c(en = "English", ma = "Mathematics"),
result = c("1" = "Very good", "2" = "Good", "3" = "Not so good")
)
## data frame which should be translated
df <- data.frame(
pupil = c(1, 1, 2, 2, 3),
subject = c("en", "ma", "ma", "en", "en"),
result = c(1, 2, 3, 2, 2)
)
## Example-1: 'lama_translate_all''
df_new <- lama_translate_all(
df,
dict,
prefix = "pre_",
fn_colname = toupper,
suffix = "_suf"
)
str(df_new)
## Example-2: 'lama_translate_all' with 'to_factor = FALSE'
# The resulting variables are plain character vectors
df_new <- lama_translate_all(df, dict, suffix = "_new", to_factor = TRUE)
str(df_new)
## Example-3: 'lama_to_factor_all'
# The variables 'subject' and 'result' are turned into factor variables
# The ordering is taken from the translations 'subject' and 'result'
df_2 <- data.frame(
pupil = c(1, 1, 2, 2, 3),
subject = c("English", "Mathematics", "Mathematics", "English", "English"),
result = c("Very good", "Good", "Good", "Very good", "Good")
)
df_2_new <- lama_to_factor_all(
df_2, dict,
prefix = "pre_",
fn_colname = toupper,
suffix = "_suf"
)
str(df_new)
# }
Run the code above in your browser using DataLab