Closed billdenney closed 6 years ago
This may be possible with something like the following:
recode.xpose_data <- function(.x, ..., .column, .default=NULL, .missing=NULL) {
for (data_idx in seq_along(.x$data$data)) {
if (.column %in% names(.x$data$data[[data_idx]])) {
.x$data$data[[data_idx]][[.column]] <-
recode(.x$data$data[[data_idx]][[.column]], ..., .default=.default, .missing=.missing)
} else {
warning("Column ", .column, " does not exist in data for problem ", data_idx)
}
}
.x
}
@billdenney recode()
can be used in xpose isn't this what you are trying to achieve?
xpdb_ex_pk %>%
mutate(SEX = dplyr::recode(SEX, `1` = 'Male', `2` = "Female")) %>%
dv_vs_ipred(type = 'p', aes(point_color = SEX))
That's exactly it! I didn't realize that mutate worked with xpose (I missed it in the docs; my oversight).
No problem!
Within NONMEM, parameters must be numbered, but it would help if we could recode parameters within xpose either by merging with a list of mapping data.frames or by running recode on the data.
As an example,
SEX = 1
isn't very informative whileSEX = "Female"
orSEX = "Male"
is (https://uupharmacometrics.github.io/xpose/articles/customize_plots.html#modify-aesthetics).A simple implementation may make a method for the
dplyr::recode()
function that would apply to xpdb objects that would also take a column name.