Sorting each row of a data frame [duplicate]

You could use the plain apply function with MARGIN = 1 to apply over rows and then transpose the result.

t(apply(df, 1, sort))

Leave a Comment