Is there a vectorized parallel max() and min()?

后端 未结 4 1541
滥情空心
滥情空心 2020-12-01 11:49

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

4条回答
  •  囚心锁ツ
    2020-12-01 12:28

    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)
    

提交回复
热议问题