How do I create a new variable in R using certain values of two variables that I already have? Specifically, my dataset has two variables for means and I only need to keep the one with the smaller value.
Here is an example:
a1 a2
x1 3 2
x2 1 5
x3 0 7
In the case of this example dataset, I would want to create a new variable "b" using only the smaller values, so for it'd be a2 for x1, a1 for x2, and a1 for x3. "b" would therefore only include the values (2,1,0). Obviously my dataset is much longer so I was wondering if there is a way to do this where I don't have to manually type it out.
Obviously my dataset is much longer so I was wondering if there is a way to do this where I don't have to manually type it out.