I have this database
# A tibble: 15 x 7
id age demo result category nationality sport
<int> <dbl> <dbl> <chr> <chr> <chr> <chr>
1 1 16 1 POS A Usa soccer
2 2 19 1 POS A Spain soccer
3 3 16 1 NEG C Spain basquet
4 4 17 1 NEG A Brasil golf
5 5 17 1 NEG B Spain voley
6 6 17 1 POS C Usa soccer
7 7 17 1 POS A Brasil voley
8 8 16 1 POS A Spain soccer
9 9 16 1 POS A France soccer
10 10 19 1 NEG B Brasil golf
11 11 17 1 POS A Brasil golf
12 12 16 0 NEG A Brasil voley
13 13 16 0 NEG B France basquet
14 14 16 0 NEG B Usa basquet
15 15 20 0 NEG A France basquet
and I need to create a column " exclusion" that has a value of 1 when the observations accomplish certain conditions and 0 when they do not. the conditions are: have an age under 18, a demo equal to 1, a result equal to NEG and sport equal to soccer. fulfilling one of the conditions already acquires a value of 1 in the column exclusio . The complicated thing is that I also want to create a column "reason" that indicates what condition the observation fulfills in order to have obtained a value of 1 in the created column. the final table I would like would be like this:
id | age | demo | result | category | nationality | sport | exclusion | reason |
---|---|---|---|---|---|---|---|---|
1 | 16 | 1 | POS | A | Usa | soccer | 1 | under 18, demo equal 1, chose soccer |
2 | 19 | 1 | POS | A | Spain | soccer | 1 | demo equal 1, chose soccer |
3 | 21 | 0 | POS | C | Spain | basquet | ||
4 | 20 | 1 | POS | A | Brasil | golf | 1 | demo equal 1 |
5 | 17 | 0 | NEG | B | Spain | voley | 1 | under 18, resul negative |
6 | 19 | 0 | POS | C | Usa | voley | ||
7 | 17 | 0 | POS | A | Brasil | voley | 1 | under 18, chose soccer |
8 | 16 | 1 | POS | A | Spain | soccer | 1 | under 18, demo equal 1, chose soccer |
9 | 19 | 0 | POS | A | France | golf | ||
10 | 19 | 0 | POS | B | Brasil | soccer | 1 | chose soccer |
11 | 21 | 0 | POS | A | Brasil | golf | ||
12 | 20 | 0 | POS | A | Brasil | voley | ||
13 | 20 | 0 | POS | B | France | basquet | ||
14 | 16 | 1 | POS | B | Usa | soccer | 1 | under 18, demo equal 1, chose soccer |
15 | 20 | 0 | NEG | A | France | soccer | 1 | resul negative, chose soccer |