I'm trying to re-scale a vector within a grouping variable. So for mtcars I would be trying scale the weight variable, but only within the grouping variable of cylinders.
First try:
mtcars2 <- mtcars %>%
group_by(cyl) %>%
nest()%>%
mutate(wt.scaled = purrr::map_dbl(wt, scale)) %>%
unnest()
ERROR: "wt" not found
2nd try:
mtcars2 <- mtcars %>%
split(.$cyl) %>%
purrr::map_dbl(wt, scale)
Error in UseMethod("mutate_") : no applicable method for 'mutate_' applied to an object of class "list"
I don't seem to know how to refer to the wt vector in the nested data.frame. Sorry if this is answered elsewhere. I spent quite a bit of time searching for the answer, but couldn't make the solutions work.