0
> DS
 datum      AUL_T ZUL_T_SW 
1  25.06.2017     21.9      22   
2  25.06.2017     21.9      22   
3  25.06.2017     21.9      22   
4  25.06.2017     21.9      22   
5  25.06.2017     21.9      22   
6  25.06.2017     21.9      22   
7  25.06.2017     21.9      22 
[ reached 'max' / getOption("max.print") -- omitted 172822 rows ]

> ifelse(DS$AUL_T < 25 || DS$ZUL_T < 22, 1, 0)
[1] NA
> ifelse(DS$AUL_T < 25, 1, 0)
   [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
  [37] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
  [73] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 [109] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1  

Not every data set has the same data points, which is why the tests should be provided with various queries (OR). If a variable from the query does not exist, this should be ignored. In the given example DS$ZUL_T is not part of the data set and thus it should only test DS$AUL_T < 25. Nevertheless, I get no result instead of multiple 1. Do you know how I can deal with this problem in R?

kaya3
  • 47,440
  • 4
  • 68
  • 97
Annika
  • 35
  • 3
  • 1
    Use `|` instead of `||`. – nicola Nov 07 '19 at 14:23
  • Not sure I understand your issue, but one thing I see is, use `|` instead of `||`, i.e., `ifelse(DS$AUL_T < 25 | DS$ZUL_T < 22, 1, 0)`. A littlebit more efficient is to just use `1 * (DS$AUL_T < 25 | DS$ZUL_T < 22)`. See also `?Logic` where it states: . The longer form (`||`) evaluates left to right examining only the first element of each vector. – David Nov 07 '19 at 14:24
  • Probably (at least) one of your columns isn't numeric. Please share your data in a copy/pasteable way that preserves the classes---`dput(droplevels(DS[1:6, ]))` would be good. – Gregor Thomas Nov 07 '19 at 14:36
  • ZUL_T is not part of this data set and that's why it should ignore the second part – Annika Nov 07 '19 at 14:42
  • then I get `> ifelse(DS$AUL_T > 25 |DS$ZUL_T > 22, 1, 0) logical(0)` but what I want is `> ifelse(DS$AUL_T > 25, 1, 0) [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ` – Annika Nov 07 '19 at 14:46

0 Answers0