Conversion of statistical test results into python not working with ri2py but they work with pandas.rpy.common

Issue #429 wontfix
Carlos Uribe
created an issue

Code Sample, a copy-pastable example if possible

from rpy2.robjects.numpy2ri import numpy2ri
from rpy2.robjects.packages import importr
from rpy2.robjects import pandas2ri
pandas2ri.activate()

r_statspackage = importr('stats',  robject_translations={'format_perc': '_format_perc'})
r_result=pandas2ri.ri2py(r_statspackage.friedman_test(numpy2ri(df.as_matrix())))
r_result

R object with classes:................................

Problem description

When I run the code above, in which I'm performing a friedman test using the R function inputting a pandas dataframe as a matrix, the r_result is still an R object that makes it difficult to work with the solution. pandas2ri.ri2py seems to be having a problem

However, when I run the following:

from rpy2.robjects.numpy2ri import numpy2ri
from rpy2.robjects.packages import importr
import pandas.rpy.common as com

r_statspackage = importr('stats',  robject_translations={'format_perc': '_format_perc'})
r_result=com.convert_robj(r_statspackage.friedman_test(numpy2ri(df.as_matrix())))

r_result is now a dictionary in which I can easily call the keys and get all the information that I need. For example r_result['p.value']

Comments (1)

  1. Log in to comment