Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205594

Generate a list of tibble from a tibble by using map and select

$
0
0

I want to generate list of tibble fron one tibble in the following codes.

tbl = tibble(id=1:10, a = rnorm(10), b = rnorm(10))
tbl_list =  c("a", "b") %>% map(~ tbl %>% select(c("id", .)))

The output I want is

tbl_list

[[1]]
# A tibble: 2 x 2
     id      a
  <int>  <dbl>
1     1 -0.704
2     2 -0.917

[[2]]
# A tibble: 2 x 2
     id      a
  <int>  <dbl>
1     1 -0.704
2     2 -0.917

However, it shows the error message,

"c("id", .) must evaluate to column positions or names, not a list" ,

so it seems that . is not recognized a character, but a list

Could you tell me how to avoid this error?


Viewing all articles
Browse latest Browse all 205594

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>