I'm trying to make a simple minimum for several columns in a data frame, but the min function automatically returns min for the entire column, and not for each row separately. I'm sure I'm missing something really simple here? Any ideas are greatly appreciated.
x<-c(1,2,7)
y<-c(1,5,4)
minIwant <- c(1,2,4)
df <- data.frame(x,y,minIwant)
df$minIget <- min(df$x,df$y)
df
x y minIwant minIget
1 1 1 1 1
2 2 5 2 1
3 7 4 4 1
source
share