Create columns from column of list in data.table

前端 未结 1 1609
无人共我
无人共我 2020-12-10 16:43

I can\'t figure out how to do the following, crating a dynamic number of columns from a column of lists with data.table

set.seed(123); N=1e5
DT          


        
1条回答
  •  囚心锁ツ
    2020-12-10 17:09

    Try this:

    DT2 <- DT[ , as.list(quantile(x,probs=probs)),by=y]
    setnames(DT2, c("y", paste0("q", seq(10, 100, by=10))))
    
    #    y       q10        q20        q30        q40          q50       q60       q70       q80
    # 1: b -1.281704 -0.8402934 -0.5251957 -0.2595748 -0.001625739 0.2526686 0.5251940 0.8379979
    # 2: c -1.269750 -0.8323597 -0.5133207 -0.2478633  0.003413041 0.2598378 0.5353759 0.8477539
    # 3: a -1.281899 -0.8389189 -0.5224092 -0.2573562  0.001186281 0.2542550 0.5244238 0.8401411
    #         q90     q100
    # 1: 1.284773 3.856234
    # 2: 1.283465 4.322815
    # 3: 1.273615 3.921410
    

    0 讨论(0)
提交回复
热议问题