With
df <- data.frame(v1=c(1:5), v2=c(9,32,6,17,11))
I need to add a new column v3 with value 1 or 0 based on whether values in v2 are larger than 10 or not so that:
df
v1 v2 v3
1 1 9 0
2 2 32 1
3 3 6 0
4 4 17 1
5 5 11 1
Is there such thing like x ? y : z in R? If not, what’s a good way to solve the above? Thanks!
ifelse(..)comes closest: