Something like this may be useful
> cbind(df[,1], t(apply(df[,-1], 1, sort)))
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 1 2 3 4 5
[2,] 2 1 2 3 6 7
[3,] 3 1 2 2 3 7
where df
is a data.frame:
df <- read.table(text="1 2 3 1 4 5
2 1 3 2 6 7
3 7 2 1 3 2", header=FALSE)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…