translating named list vectors from R into rpy2 in Python?

你。 提交于 2019-12-05 08:04:23

If I understand right your question what you are looking for is a TaggedList:

import rpy2.rlike.container as rlc
Var1 = rlc.TaggedList(["navy","darkgreen"], tags=('Class1', 'Class2'))

See http://rpy.sourceforge.net/rpy2/doc-2.2/html/rlike.html for more details.

After many hours of trial and error, I found the solution. I don't fully understand why the similar variants of this did not work, or why this scheme is not interchangeable with dataframes, but what I got to work is:

anno_colors = robj.StrVector(tuple(["navy", "green"]))
anno_colors.names = ["Class1", "Class2"]
od = OrderedDict()
od["Type"] = anno_colors
result = robj.ListVector(od)
print str(result)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!