R数据框单元格包含数据框/小标题-如何访问或可视化?

问题描述 投票:0回答:1

优秀的包inspectdf产生小标题输出,其中一列包含另一小标题(或列表)。示例数据位于此问题底部的dput中,如下所示:

> test
# A tibble: 4 x 10
  col_name     min    q1 median    mean    q3     max       sd pcnt_na hist             
  <chr>      <dbl> <dbl>  <dbl>   <dbl> <dbl>   <dbl>    <dbl>   <dbl> <list>           
1 contacts    0       1      1     4.14    2     480     14.9    1.10  <tibble [26 x 2]>
2 pop         0.02  735.  2225. 4651.   4722. 289825. 10590.     0.082 <tibble [17 x 2]>
3 limit       0     750   1000  5994.   3500  500000  33355.     0.055 <tibble [27 x 2]>
4 code_count  1       1      1     1.72    2      43      1.50   0     <tibble [24 x 2]>

其中所讨论的列的内容包含:

> test$hist[1]
[[1]]
# A tibble: 26 x 2
   value          prop
   <chr>         <dbl>
 1 [-Inf, 0)  0       
 2 [0, 20)    0.961   
 3 [20, 40)   0.0200  
 4 [40, 60)   0.00696 
 5 [60, 80)   0.00352 
 6 [80, 100)  0.00200 
 7 [100, 120) 0.00144 
 8 [120, 140) 0.000837
 9 [140, 160) 0.000696
10 [160, 180) 0.000459
# ... with 16 more rows

问题是,如何使最后一列可访问或能够在显示机制内可视化?例如,当我使用DT时,它会将[object: Object]放在最右边的列中,而不是我想要的一些有用的东西,例如可能用于查看或弹出嵌入数据的链接:

library(DT)
test %>% DT::datatable()

enter image description here

是否有使用迷你图或建立链接的方法,或以其他任何方式显示最后一列的内容?欢迎使用所有方法(如果DT内有某种方法可以实现,那将是理想的选择)。谢谢您的帮助。

test <- structure(list(col_name = c("contacts", "pop", "limit", "code_count"
), min = c(0, 0.02, 0, 1), q1 = c(1, 735.1, 750, 1), median = c(1, 
2224.73, 1000, 1), mean = c(4.142, 4651.211, 5994.002, 1.717), 
q3 = c(2, 4721.56, 3500, 2), max = c(480, 289825.16, 5e+05, 
43), sd = c(14.926, 10590.427, 33354.671, 1.501), pcnt_na = c(1.103, 
0.082, 0.055, 0), hist = list(structure(list(value = c("[-Inf, 0)", 
"[0, 20)", "[20, 40)", "[40, 60)", "[60, 80)", "[80, 100)", 
"[100, 120)", "[120, 140)", "[140, 160)", "[160, 180)", "[180, 200)", 
"[200, 220)", "[220, 240)", "[240, 260)", "[260, 280)", "[280, 300)", 
"[300, 320)", "[320, 340)", "[340, 360)", "[360, 380)", "[380, 400)", 
"[400, 420)", "[420, 440)", "[440, 460)", "[460, 480)", "[480, Inf)"
), prop = c(0, 0.961394177780924, 0.0200167851400953, 0.00696279968047565, 
0.00352285711396706, 0.00199601605710992, 0.00143785959129195, 
0.000837234698726958, 0.000695673276236893, 0.000459063470074926, 
0.00138527963436707, 0.00129023125069517, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 2.02230603557236e-06, 0)), row.names = c(NA, 
-26L), class = c("tbl_df", "tbl", "data.frame")), structure(list(
    value = c("[-Inf, 0)", "[0, 20000)", "[20000, 40000)", 
    "[40000, 60000)", "[60000, 80000)", "[80000, 1e+05)", 
    "[1e+05, 120000)", "[120000, 140000)", "[140000, 160000)", 
    "[160000, 180000)", "[180000, 2e+05)", "[2e+05, 220000)", 
    "[220000, 240000)", "[240000, 260000)", "[260000, 280000)", 
    "[280000, 3e+05)", "[3e+05, Inf)"), prop = c(0, 0.965121399547629, 
    0.0219419924337957, 0.00583678616465502, 0.00279829460157329, 
    0.00160731800076062, 0.00102283872775676, 0.000630517023959647, 
    0.000388318421105306, 0.000296242919193739, 0.000178146079785424, 
    6.40525230689165e-05, 6.20508817230129e-05, 4.60377509557837e-05, 
    4.00328269180728e-06, 2.00164134590364e-06, 0)), row.names = c(NA, 
-17L), class = c("tbl_df", "tbl", "data.frame")), structure(list(
    value = c("[-Inf, 0)", "[0, 20000)", "[20000, 40000)", 
    "[40000, 60000)", "[60000, 80000)", "[80000, 1e+05)", 
    "[1e+05, 120000)", "[120000, 140000)", "[140000, 160000)", 
    "[160000, 180000)", "[180000, 2e+05)", "[2e+05, 220000)", 
    "[220000, 240000)", "[240000, 260000)", "[260000, 280000)", 
    "[280000, 3e+05)", "[3e+05, 320000)", "[320000, 340000)", 
    "[340000, 360000)", "[360000, 380000)", "[380000, 4e+05)", 
    "[4e+05, 420000)", "[420000, 440000)", "[440000, 460000)", 
    "[460000, 480000)", "[480000, 5e+05)", "[5e+05, Inf)"
    ), prop = c(0, 0.962615288870034, 0.00958330915327091, 
    0.0104617958348925, 0.00314974495870712, 0, 0.00967936236675118, 
    0, 5.00277153543063e-05, 0, 0, 8.80487790235791e-05, 
    0, 0.000580321498109953, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0.00379210082385642, 0)), row.names = c(NA, -27L), class = c("tbl_df", 
"tbl", "data.frame")), structure(list(value = c("[-Inf, 0)", 
"[0, 2)", "[2, 4)", "[4, 6)", "[6, 8)", "[8, 10)", "[10, 12)", 
"[12, 14)", "[14, 16)", "[16, 18)", "[18, 20)", "[20, 22)", 
"[22, 24)", "[24, 26)", "[26, 28)", "[28, 30)", "[30, 32)", 
"[32, 34)", "[34, 36)", "[36, 38)", "[38, 40)", "[40, 42)", 
"[42, 44)", "[44, Inf)"), prop = c(0, 0.663122, 0.251104, 
0.054242, 0.01933, 0.007962, 0.002444, 0.000946, 0.00032, 
0.00016, 8.4e-05, 4e-05, 1.4e-05, 1.2e-05, 8.4e-05, 0.000102, 
1.6e-05, 0, 4e-06, 2e-06, 2e-06, 4e-06, 6e-06, 0)), row.names = c(NA, 
-24L), class = c("tbl_df", "tbl", "data.frame")))), row.names = c(NA, 
-4L), class = c("tbl_df", "tbl", "data.frame"))
r datatable dt tibble sparklines
1个回答
0
投票

您可能希望unnestunnest_wider保留在同一数据帧中。

Unnest a list column directly into several columns

© www.soinside.com 2019 - 2024. All rights reserved.