13.4 Mutate grammar and missing results
--mutate changes or creates columns using assignments separated by semicolons. Assignments run from left to right, so later expressions can use earlier results. Existing columns are replaced case-insensitively; new columns are appended to the generated dataset.
nlmx eda data.csv --mutate "BMI = WT/(HT/100)^2; LOGDV = log(DV)"
Supported expression building blocks
Assignments accept = or <-. Arithmetic includes +, -, *, /, and exponentiation ^. Comparisons, &, |, and ! yield numeric truth values (1 or 0). Membership uses %in% c(...). Text values are quoted.
Supported functions include natural log, log(x, base), log10, log2, exp, sqrt, abs, round(x,digits), floor, ceiling, trunc, element-wise min/pmin and max/pmax, ifelse, is.na, paste, and paste0. This is an R-like expression language, not a complete R interpreter; test complicated transformations explicitly.
Missing and infinite results
A missing input or invalid calculation—such as log(0), square root of a negative value, or division by zero—becomes . in the mutated dataset. The log reports affected row counts. That behavior prevents an infinity from silently entering plots, but it does not make the transformation scientifically appropriate.
Dose rows commonly have missing DV, so LOGDV=log(DV) may legitimately be missing there. Review missingness separately on observation records before deciding a warning is harmless.
Common mistakes
- Assuming all R functions or grouped/window operations are available.
- Creating a derived column after a filter that already references it.
- Logging values without checking zeros, negatives, or units.
- Replacing DV and forgetting that all standard plots now use the replacement.
Checklist
- Break complex transformations into named sequential assignments.
- Test domain restrictions and missing inputs.
- Compare original and mutated values on sample rows.
- Record units for every derived column.
- Preserve and review the generated dataset.
Further reading
See processing order, recipes, and worked example.