'check for a value to pick an ID in r
I have total 10 columns in a df and for 3 to 10 columns I need to check if there is a value 0 or 1 row wise. If there is value 1 in any of rows then select the id (R language)
test<-df %>%
group_by(id) %>%
filter(all(if_any(sympt3:sympt10, as.logical)))
id date
symptom1
1 2011-08-27 0
2 2012-02-21 1
3 2012-07-12 0
4 2012-07-25 0
5 2010-12-31 0
6 2011-01-02 0
7 2012-08-21 0
8 2013-03-26 0
9 2012-11-07 0
10 2010-11-22 0
symptom 2 symptom 3
1 0 0
2 1 1
3 0 0
4 0 0
5 0 0
6 0 1
7 0 0
8 1 0
9 0 0
10 0 0
symptom 5. symptom 6
1 1 0
2 0 1
3 0 0
4 0 0
5 0 0
6 1 0
7 0 1
8 0 0
9 0 0
10 0 1
symptom 7 symptom 8
1 1 0
2 0 1
3 0 0
4 0 0
5 1 0
6 0 0
7 1 1
8 0 0
9 0 0
10 1 0
I'm not sure if I'm selecting the ids which has value 1 from any of the columns I need?
Any help is appreciated
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
