I have a data.frame with columns \"a\" and \"b\". I want to add columns called \"high\" and \"low\" that contain the highest and the lowest among columns a and
data.frame
Another possible solution:
set.seed(21) Data <- data.frame(a=runif(10),b=runif(10)) Data$low <- apply(Data[,c("a","b")], 1, min) Data$high <- apply(Data[,c("a","b")], 1, max)