I have a tibble which I would like to extend with a new column containing tibbles.
Example code:
test = tribble(~a, ~b,
1, 2,
3, 4
)
mutate(test, mynewcol = tribble(~c,999))
However, this will produce:
Error: Column `mynewcol` is of unsupported class data.frame
So it seems I cannot extend tibbles via mutate with nested tibbles - but I can create them this way?
test2 = tribble(~a, ~b, ~mynewcol,
1, 2, tribble(~c,999),
3, 4, tribble(~c,999)
)
print(test2)
So what would be the correct way of adding those nested tibbles into my tibble? I know I can work with bind_cols to glue on a new tibble, but it would be nice if I could add my new values depending on other variables in the row - which is something that mutate can usually do nicely; so something like this:
mutate(test2, mynewcol = ifelse(a > 2, tribble(~xx, "xxx"),tribble(~yy, "yyy")))