First, I created a data frame like below:
age=18:29
height=c(76.1,77,78.1,78.2,78.8,79.7,79.9,81.1,81.2,81.8,82.8,83.5)
height1=c(71.1,75,77.1,73.2,77.8,73.7,78.9,87.1,86.2,85.8,82.8,83.5)
village=data.frame(age=age,height=height,height1=height1)
Now, I want to create a fourth column in the data frame that takes the height of the shorter person per each row, e.g. row 1 76.1 vs 71.1 should return 71.1 and so on.
I tried doing this with this code:
village=transform(village, shorter=min(height,height1))
And I got an odd result. It gives me the absolute smallest value in BOTH columns:
How can I modify this function to give me the lower value on a row-by-row basis?