Converting an RPy2 ListVector to a Python dictionary

前端 未结 7 1206
日久生厌
日久生厌 2020-12-09 16:46

The natural Python equivalent to a named list in R is a dict, but RPy2 gives you a ListVector object.

import rpy2.robjects as robjects

a = robjects.r(\'list         


        
7条回答
  •  既然无缘
    2020-12-09 17:25

    With the new version of pandas, one could also do,

    import rpy2.robjects as robjects
    a = robjects.r('list(foo="barbat", fizz=123)')
    
    from rpy2.robjects import pandas2ri
    print(pandas2ri.ri2py(a.names))
    temp = pandas2ri.ri2py(a)
    print(temp[0])
    print(temp[1])
    

提交回复
热议问题