I have a numeric vector:
p = c(0.69, 0.43, 0.72, 0.62, 0.29, 0.7)
I wish to compare the values to a limit, e.g. 0.5. If the values are equal or larger than the cut-off, the result should 1. Values less than 0.5 should become 0.
I tried ifelse
, but it errors:
newvector = rep(0, length(p))
newvector = ifelse(p >= 0.5, newvector = 1, newvector = 0)
# Error in ifelse(p >= 0.5, newvector = 1, newvector = 0) :
# unused arguments (newvector = 1, newvector = 0)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…