如何将R中保存为RData的字符向量导入到python列表中?
例如,如果我在R:
中保存了这个字符向量x <- c("Hello", "world!")
save (x, file = 'x.RData')
然后使用rpy2
加载到python中,如下所示:
from __future__ import print_function
from rpy2.robjects import pandas2ri,r
import rpy2.robjects as robjects
def main():
r['load']('x.RData')
variables = tuple(robjects.globalenv.keys())
print('variables: {0}'.format(variables))
x = robjects.globalenv['x']
print('x: {0}'.format(x))
print('type(x): {0}'.format(type(x)))
if __name__ == "__main__":
main()
打印:
variables: ('x',)
x: [1] "Hello" "world!"
type(x): <class 'rpy2.robjects.vectors.StrVector'>
如何将其导入python列表?
答案 0 :(得分:0)
您只需使用pointer-events
:
list()