0

I have a data frame with two columns with words. Every row I need the first column to have the alphabetically earlier one. For example. say I have this data frame with 3 rows.

   MYL9   TGFB1I1
   GPR174  CD3G    
   HAT1    ARL6IP6 

The result should be:

   MYL9   TGFB1I1
   CD3G    GPR174      
   ARL6IP6  HAT1  

The problem is I have a huge array of these and I am looking to see if there is af fast way of doing this instead of a for loop.

user1775614
  • 439
  • 7
  • 12
  • 1
    `t(apply(mydf, 1, sort))`? – A5C1D2H2I1M1N2O1R2T1 Nov 11 '15 at 19:13
  • 1
    With only two columns to sort, different solutions are available, like with example `DF= data.frame(V1=c("M","G","H"), V2=c("T","C","A"))` you can do `idx = which(DF[[1]] > DF[[2]]); DF[idx, 1:2] <- DF[idx, 2:1]` @MrFlick – Frank Nov 11 '15 at 19:27
  • @Frank It would be more useful to add that answer as a special case for one of the many existing duplicates. – MrFlick Nov 11 '15 at 19:30

0 Answers0