So I have a simple data frame, a bunch of names, each with ~2,000 rows of varying numeric values each. There's a function I want to use in my analysis that takes in numeric vectors only, and I want to iterate that function over each name's values in my data frame.
Using nest() creates a tibble for each name (see below). What I am trying to do is have each element be a vector, not an one-column tibble.
library(tidyverse)
df <- tibble(
name = c(rep("Adam",5), rep("Liz",5)),
value = c(1:5, 21:25)
)
df
#> # A tibble: 10 x 2
#> name value
#> <chr> <int>
#> 1 Adam 1
#> 2 Adam 2
#> 3 Adam 3
#> 4 Adam 4
#> 5 Adam 5
#> 6 Liz 21
#> 7 Liz 22
#> 8 Liz 23
#> 9 Liz 24
#> 10 Liz 25
df %>%
nest(-name)
#> # A tibble: 2 x 2
#> name data
#> <chr> <list>
#> 1 Adam <tibble [5 × 1]>
#> 2 Liz <tibble [5 × 1]>
### What I think I want:
#> # A tibble: 2 x 2
#> name data
#> <chr> <list>
#> 1 Adam <dbl [5]>
#> 2 Liz <dbl [5]>
Created on 2019-05-23 by the reprex package (v0.2.1)
I've played around with unlist(), pluck(), pull() mixed with assorted map()s but none of them are getting me where I need to be.
Thanks in advance!