Hi, I get this error: Argument 1 must have names
here is the code:
expand_grid(x = c(1, 3, 9), y = c(4, 6, 2)) %>%
pmap(sum)
It works, but I wanted to have a dataframe as an output, so I have done:
expand_grid(x = c(1, 3, 9), y = c(4, 6, 2)) %>%
pmap_df(sum)
doesn't work with error:
Error: Argument 1 must have names.
So next, I have done:
expand_grid(x = c(1, 3, 9), y = c(4, 6, 2)) %>% as.data.frame(.) %>% set_names(paste0('V', 1:2)) %>% pmap_df(.,sum)
but still the same error:
Error: Argument 1 must have names.
Run `rlang::last_error()` to see where the error occurred.
and:
rlang::last_error()
<error/rlang_error>
Argument 1 must have names.
Backtrace:
1. `%>%`(...)
2. purrr::pmap_df(., sum)
3. dplyr::bind_rows(res, .id = .id)
Run `rlang::last_trace()` to see the full context.
and:
rlang::last_trace()
<error/rlang_error>
Argument 1 must have names.
Backtrace:
x
1. +-`%>%`(...)
2. \-purrr::pmap_df(., sum)
3. \-dplyr::bind_rows(res, .id = .id)
but this works:
expand_grid(x = c(1, 3, 9), y = c(4, 6, 2)) %>%
pmap_dfc(sum)
Why is that, could anybody explain, please ?
My desired output woud be having three variables: V1, V2 and V3 as sum in dataframe.