Transposing JSON list-of-dictionaries for analysis in R

后端 未结 2 1794
眼角桃花
眼角桃花 2021-02-02 03:51

I have experimental data expressed as dicts of key-value pairs for each experiment. A set of related experiments is serialized as a list of these dicts in JSON. This is parseabl

2条回答
  •  自闭症患者
    2021-02-02 04:07

    This is interesting. The easiest way would be to fix the Python code so that the dict can be transformed more easily.

    But, how about this?

    k1 <- unlist(lapply(data,FUN=function(x){return(x[[1]])}))
    k2 <- unlist(lapply(data,FUN=function(x){return(x[[2]])}))
    data.frame(k1,k2)
    

    You will need to cast k1 and k2 into the correct data type still, but this should accomplish what you are looking for.

提交回复
热议问题