Filter based on multiple conditions

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)
Post Reply
tcford
Posts: 7
Joined: Wed Jun 20, 2018 2:41 am

Filter based on multiple conditions

Post by tcford »

Hi all,
I am trying to filter out rows where two conditions are met (e.g., sex and age over 40). I can create a filter that removes all cases that are males and all cases that are over 40 years (sex != "M" and age < 40), but what if I only want to filter out males who are over 40? So all males under the age of 40 remain active?
My apologies if this question has been answered already. I have tried a number of variations but cant seem to work it out.
Thanks,
Talitha
User avatar
MAgojam
Posts: 421
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Filter based on multiple conditions

Post by MAgojam »

Hi Talitha,
The filter has the purpose of selecting only the data that supports it and excluding the others for the statistics that you are going to use, but also updating those you have already done.
In your case, if you want to run statistics that only include cases where the Sex variable is "M" to select only males and the Age variable must only have values greater than 40 years, you can filter:
Sex == 'M' and Age> 40
You can see the attached screenshot.
screenshot_filter.png
screenshot_filter.png (63.82 KiB) Viewed 8583 times
Greetings and Happy Easter.
Maurizio
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Filter based on multiple conditions

Post by jonathon »

maurizio is spot-on,

but another thing you can do is use the '+' button to the top left of the filters. this way you can create separate filters:

the first one: `Sex == 'M'`, and `Age > 40` for the second one. the nice thing about doing them separately, is you can see at a glance why a row was excluded. but both ways work.

cheers

jonathon
enricocmendoza
Posts: 15
Joined: Fri Oct 23, 2020 9:12 am

Re: Filter based on multiple conditions

Post by enricocmendoza »

jonathon wrote:maurizio is spot-on,

but another thing you can do is use the '+' button to the top left of the filters. this way you can create separate filters:

the first one: `Sex == 'M'`, and `Age > 40` for the second one. the nice thing about doing them separately, is you can see at a glance why a row was excluded. but both ways work.

cheers

jonathon
Hi Jonathon,

Good day. Can i ask you for the command if i want to filter the following: I only want to include ages between 25 and 34, and countries only like Sweden, Norway, Finland, Denmark in my analysis. I am using GEM data set. Hope you can help me on this. Thank you very much.

Warm regards,

Enrico Mendoza
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Filter based on multiple conditions

Post by jonathon »

i'd create two filters

25 < age < 34

country == 'Sweden' or country == 'Norway' or country == 'Finland' or country == 'Denmark'

jonathon
tcford
Posts: 7
Joined: Wed Jun 20, 2018 2:41 am

Re: Filter based on multiple conditions

Post by tcford »

Hello, I'm back again. What if I want to filter out rows where 2 conditions are met. For example have a column of participant IDs (1,2,3, etc) and a column of treatments (A,B). Each participant has 4 rows (4 time points [T1-T4]), where they have treatment A for 2 time-points and treatment B for the other 2.
How would I exclude the rows for participant 1 AND ONLY condition B, leaving participant 1 and condition A as active in the data?
Thanks for your help!
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Filter based on multiple conditions

Post by jonathon »

> leaving participant 1 and condition A as active in the data?

participant == 1 and condition == 'A'
Post Reply