dunlin
:
Tools for Clinical Trial Data Wrangling
dunlin
provides a variety of data tools to reformat and
manipulate a subset of the tables in a data set.
# install.packages("pak")
::pak("insightsengineering/dunlin@*release") pak
Alternatively, you might also use the development version.
# install.packages("pak")
::pak("insightsengineering/dunlin") pak
library(dunlin)
<- data.frame(
df1 "id" = c("a", "b", NA, "a", "k", "x"),
"id2" = factor(c("f1", "f2", NA, NA, "f1", "f1")),
"val" = letters[1:6]
)<- data.frame(
df2 "id" = c("a", "b", NA, "a", "k", "x"),
"id2" = factor(c("f1", "f2", NA, NA, "f1", "f1")),
"num" = 1:6
)
<- list(df1 = df1, df2 = df2)
db
<- propagate(db, "df1", "val", c("id", "id2")) prop_db
which returns prop_db
as
$df1
id id2 val
1 a f1 a
2 b f2 b
3 <NA> <NA> c
4 a <NA> d
5 k f1 e
6 x f1 f
$df2
id id2 num val
1 a f1 1 a
2 b f2 2 b
3 <NA> <NA> 3 c
4 a <NA> 4 d
5 k f1 5 e
6 x f1 6 f
<- list(
new_format df1 = list(
id = rule("No ID available" = c("", NA, "<Missing>")),
id2 = rule("<Missing>" = c("", NA, "<Missing>"))
)
)
<- reformat(prop_db, new_format, .na_last = TRUE) res
which result in res
as
$df1
id id2 val
1 a f1 a
2 b f2 b
3 No ID available <Missing> c
4 a <Missing> d
5 k f1 e
6 x f1 f
$df2
id id2 num val
1 a f1 1 a
2 b f2 2 b
3 <NA> <NA> 3 c
4 a <NA> 4 d
5 k f1 5 e
6 x f1 6 f