I have data.frame
df <- data.frame(a = c(1,3),b = c(2,4))
a b
1 1 2
2 3 NA
and I want to receive a data.frame like this:
a b json
1 1 2 {"a":1, "b":2}
2 3 NA {"a":3}
I wonder if there is a way to get this result efficiently with
df <- df %>% dplyr::mutate(json = ?())
without pasting values myself. In Postgres there is a function json_strip_nulls(row_to_json(*))
to get this. Is there any equivalent in R?