Let's say if I have the following data
x <- rnorm(100)
I want to create another column where where if x
is equal to or greater than 0.2, give it a value of 1 or else 0.
We can create the logical condition and wrap with +
xNew <- +(x >=0.2)
If we need a data.frame
,
dat <- data.frame(x, xNew)
Or use ifelse
xNew <- ifelse(x >= 0.2, 1, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With