This is happening because the signature of the R function is:
base::mean(x, ...)

No na.rm in sight, therefore no na_rm by default on the Python side - 
see http://rpy.sourceforge.net/rpy2/doc-dev/html/robjects_functions.html

r['mean_default'](data_NA, na_rm=True)

or

r.mean(data_NA, **{'na.rm': True})

should work.


L.

On 2011-10-05 14:26, William T. Martin wrote:
> How do I specify na.rm=True to ignore NA vector values?
>
> The following code:
>
> import rpy2.robjects as ro
> import rpy2.rinterface as ri
>
> r=ro.r
> data=ro.FloatVector([10, 20, 30])
> print(data)
> m=r.mean(data, na_rm=ri.TRUE)
> print(m)
>
> data_NA=ro.FloatVector([10, 20, 30, ro.NA_Real])
> print(data_NA)
> m_NA=r.mean(data_NA, na_rm=ri.TRUE)
> print(m_NA)
>
> produces:
>
>   >>>  import rpy2.robjects as ro
>   >>>  import rpy2.rinterface as ri
>   >>>
>
>   >>>  data_NA=ro.FloatVector([10, 20, 30, ro.NA_Real])
>   >>>  print(data_NA)
> [1] 10 20 30 NA
>
>   >>>  m_NA=r.mean(data_NA, na_rm=ri.TRUE)
>   >>>  print(m_NA)
> [1] NA
>
>
> A simple R program gives the following:
>
>   >  data_NA<-c(10,  20, 30, NA)
>   >  mean(data_NA)
> [1] NA
>   >  mean(data_NA, na.rm=TRUE)
> [1] 20
>
> Thank you
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to