首页 > 解决方案 > 在嵌套的df中使用地图提取数据

问题描述

我有一个数据框nested_df

   sample condition data                             
 1 hbr_2d treated   <tibble [2,806 x 3]>
 2 hbr_3d treated   <tibble [2,757 x 3]>
 3 hbr_ev treated   <tibble [2,752 x 3]>
 4 hct_2d treated   <tibble [2,756 x 3]>
 5 hct_3d treated   <tibble [2,743 x 3]>
 6 hct_ev treated   <tibble [2,731 x 3]>
 7 pbr_2d treated   <tibble [2,502 x 3]>
 8 pbr_3d treated   <tibble [2,674 x 3]>
 9 pbr_ev treated   <tibble [2,661 x 3]>
10 pmf_2d treated   <tibble [2,598 x 3]>
11 pmf_3d treated   <tibble [2,599 x 3]>
12 pmf_ev treated   <tibble [2,469 x 3]>
nested_df$data
[[1]]
   protein    value presence  
 1 A0A024QYZ9  16.8 Yes     
 2 A0A024QZ21  15.1 Yes     
 3 A0A024QZ72  15.0 Yes     
 4 A0A024QZA8  19.0 Yes     
 5 A0A024QZB1  13.7 Yes     
 6 A0A024QZK9  19.1 Yes     
 7 A0A024QZV7  19.8 Yes     
 8 A0A024R023  16.2 Yes     
 9 A0A024R032  18.0 Yes     
10 A0A024R0G5  11.1 Yes  

我想逐行拉出列表proteinsample

预期结果:

[[hbr_2d]]
[1] "A0A024QYZ9" "A0A024QZ21" "A0A024QZ72" "A0A024QZA8" "A0A024QZB1" "A0A024QZK9" "A0A024QZV7"
[8] "A0A024R023" "A0A024R032"

[[hbr_3d]]
[1] "A0A024QYZ9" "A0A024QZ21" "A0A024QZ72" "A0A024QZA8" "A0A024QZB1" "A0A024QZK9" "A0A024QZV7"
[8] "A0A024R023" "A0A024R032"

我曾尝试使用map诸如地图之类的方法,但这不起作用。

map(nested_df, ~.x[] %>% pull())

Error in UseMethod("pull") : 
  no applicable method for 'pull' applied to an object of class "character"

我应该如何编码?感谢你的帮助。

标签: rdplyrpurrr

解决方案


推荐阅读