You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Love the package but I keep running into the need to change a field in only a subset of the elements in the list. Is there a way to do this today?
For example, something like:
foo <- list(
list(a = 1, b = 10),
list(a = 2, b = 20),
list(a = 3, b = 30)
)
# change field 'b' to 300 in each list element where field 'a' is a 3
foo <- foo |>
rlist::list.update_with_condition(a == 3, b = 300)
giving:
list(
list(a = 1, b = 10),
list(a = 2, b = 20),
list(a = 3, b = 300)
)
Today, I end up doing it with lapply:
# change field 'b' to 300 in each list element where field 'a' is a 3
foo <- lapply(foo, function(x) {
if (x$a == 3) {
x$b <- 300
}
x
})
The text was updated successfully, but these errors were encountered:
Love the package but I keep running into the need to change a field in only a subset of the elements in the list. Is there a way to do this today?
For example, something like:
giving:
Today, I end up doing it with lapply:
The text was updated successfully, but these errors were encountered: