This is my small reproducible example for a dataset I'm working on:
set.seed(123)
dat <- as.data.frame( cbind(a=1+round(runif(5), 2), b=round(rnorm(5), 2), high_cutoff=round(1+rnorm(5), 1)) )
Information frame:
a b high_cutoff
1.29 -1.69 2.3
1.79 1.24 -0.7
1.41 -0.11 2.7
1.88 -0.12 1.5
1.94 0.18 3.5
I am trying to check if there is at least one value in the first two columns in the row that is higher than the correction threshold in the third column (let's say that I want to keep 1 if either of the two values is higher than the cutoff).
In this example, I should find the following:
higher_than_cutoff
0
1
0
1
0
I tried to use the following (incorrect) code and some of its variants without much success:
higher_than_cutoff <- apply( dat[, c("a", "b")], 1, function(x) any(x > dat[, "high_cutoff"]) )
Can you give some tips on how to proceed? Any help is much appreciated
source
share