Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

R vectorize comparison to lists of start and end vectors, respectively

$
0
0

I have:

  • a dataframe DATA containing many numeric columns with the names: X1, X2, X3, ... (the number of columns is variable)
  • numeric vectors start1, start2, start3, ... (as many as the columns of DATA) and End1, End2, End3, ... (as many as the columns of DATA)

I want to add a column called Result to DATA, where the nth element of Result: DATA$Result[n] is TRUE if all the following conditions are true:

  • nth value of DATA$X1 is between start1[n] and End1[n] and
  • nth value of DATA$X2 is between start2[n] and End2[n] and....

How can I do this?


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>