Converting a data.frame to a list of lists

前端 未结 5 2078
梦如初夏
梦如初夏 2020-12-09 20:50

How can I convert a data.frame

df <- data.frame(id=c(\"af1\", \"af2\"), start=c(100, 115), end=c(114,121))

To a list of lists

         


        
5条回答
  •  伪装坚强ぢ
    2020-12-09 21:03

    If, like me, you are mostly looking to create lists of lists to use in highcharter, that same package contains the function list_parse() (or list_parse2() if you want to remove names). Simply use it like so:

    library(highcharter)
    
    df <- data.frame(id=c("af1", "af2"), start=c(100, 115), end=c(114,121))
    
    LoL <- list_parse(df)
    

    After which you can do the indexing you wanted:

    > LoL[[1]]$start
    [1] 100
    

提交回复
热议问题