我正在尝试通过 python 使用 r 的密度函数,我必须将“from”、“to”参数传递给密度函数。但是,由于“from”这个词是 python 中的保留关键字,我该如何实现呢? 谢谢。 这是到目前为止的代码。
r_density=robjects.r('density')
f_a = robject.FloatVector(a)
r_a = r_density(f_a, bw='SJ', n=1024) ## Here I need to add 'from' and 'to' arguments
最佳答案
你可以使用dict
argument-unpacking将保留字作为参数名称传递:
r_a = r_density(f_a, bw='SJ', n=1024, **{'from':1, 'to':3})
或
r_a = r_density(f_a, **{'bw':'SJ', 'n':1024, 'from':1, 'to':3})
关于python - rpy2 传递 python 保留关键字参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41901917/