Question

I have a data frame with, amongst others, 2 columns called data_type and input_type.

To obtain the subset of the data frame where data_type column has a certain value I can use:

subset_frame = dataframe.rx(dataframe.rx2('input_type').ro == 'VALUE', True)

I can do the same on column input_type. However I haven't managed to work out how to combine these 2 conditions in one operation. From the rpy2 docs, what I expect should work is

new_frame = dataframe.rx((dataframe.rx2('input_type').ro == 'VALUE1').ro 
                              & dataframe.rx2('data_type').ro == 'VALUE2').ro, 
                              True)

However this also doesn't work. What's the correct way of doing this?

Was it helpful?

Solution

One .ro is in excess:

new_frame = all_data_frame.rx((dataframe.rx2('input_type').ro == 'VALUE1').ro 
                               & (dataframe.rx2('data_type').ro == 'VALUE2'), 
                              True)

Otherwise this might change to and, not &. The later is a bitwise operator in Python.

>>> 1 & 2 # 0b01 & 0b10
0
>>> 1 & 3 # 0b01 & 0b11
1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top