flatten a data frame

前端 未结 2 1287
独厮守ぢ
独厮守ぢ 2021-02-13 05:13

I have this nested data frame

test <- structure(list(id = c(13, 27), seq = structure(list(
`1` = c(\"1997\", \"1997\", \"1997\", \"2007\"),
`2` = c(\"2007\",         


        
2条回答
  •  逝去的感伤
    2021-02-13 05:37

    This is not an answer but a follow up/supplement to Paul's answer:

    Consistently on any number of iterations the c method performs the best. However as I increased the number of iterations to 100000 unlist went from the poorest to very close to the c method.

    1000 iterations

         test replications elapsed relative user.self sys.self user.child sys.child
    2       c         1000    0.04 1.333333      0.03        0         NA        NA
    1 do.call         1000    0.03 1.000000      0.03        0         NA        NA
    3  unlist         1000    0.23 7.666667      0.04        0         NA        NA
    

    100,000 iterations

         test replications elapsed relative user.self sys.self user.child sys.child
    2       c       100000    8.39 1.000000      3.62        0         NA        NA
    1 do.call       100000   10.47 1.247914      4.04        0         NA        NA
    3  unlist       100000    9.97 1.188319      3.81        0         NA        NA
    

    Again thanks for sharing Paul!

    Benchmarking performed using rbenchmark on a win 7 machine running R 2.14.1

提交回复
热议问题