I'm trying to create a factor from vector d
that indicates whether each value of d
is missing, less than threshhold
, or greater than/equal to threshhold
. I attempted with the following code, using the cases
function from the memisc
package.
threshhold = 5
d <- sample(c(1:10, NaN), 50, replace=TRUE)
d_case <- cases(
is.na(d),
d > threshhold,
d <= threshhold
)
and got a warning: In cases(is.na(d), d > threshhold, :
condition is.na(d) is never satisfied
.
I've also tried using assignment operators,
d_case <- cases(
is.na(d) -> 0,
d > threshhold -> 1,
d <= threshhold -> 2
)
and got the same warning. I've checked, and d
does contain NaN
values, which is.na()
should be returning as true (and is, when I check it outside of cases). Does anyone know why cases isn't working, or what I can do to get the indicator factor I need?