使用rpy2.robjects将Python integer转换为R integer格式

2024-04-25 00:44:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用rpy2模块用python编写R代码。Python代码中有一个整数,我想使用rpy2.robjects将其转换为R integer格式。我该怎么做

我只能找到robjects.Intvector,但这只能将整数元组转换为R的向量格式

i = robjects.IntVector((1, 3))

在下面的代码中,我展示了如何将python日期格式转换为R日期格式。我想用rpy2.robjects对整数做类似的处理

import datetime 

now = datetime.datetime.now()
today_date = now.date()

train_duration = 14 

# Convert Python objects to R objects.
today_date = base.as_Date(today_date.strftime("%Y-%m-%d"))

# How to convert train_duration using r_objects ?

Tags: 模块to代码todaydatetimedateobjects格式