0

I have a data frame which looks like the following

   GR1-text GR11-text GR12-text GR2-text
A    1          1       0          0
B    1          0       1          1

I want to sort the dataframe to look like:

   GR1-text  GR2-text  GR11-text  GR12-test
A   1         0         1           0
B   1         1         0           1

I have tried the following which has not worked

test <- df[ , order(names(df))]

Ive also spotted this custom function but I cannot seen to get it to work.

AudileF
  • 436
  • 2
  • 10

1 Answers1

0

Try with order(readr::parse_number(names(df))).

F. Privé
  • 11,423
  • 2
  • 27
  • 78
  • Thanks for this @F.Prive. but I get an error `Warning: 43 parsing failures. row # A tibble: 5 x 4 col row col expected actual expected actual 1 82 NA a number - row 2 83 NA a number - col 3 84 NA a number - expected 4 85 NA a number - actual 5 86 NA a number - ... ........ See problems(...) for more details.` – AudileF Jul 14 '17 at 08:30
  • Can you provide all the names? Or put the `parse_number()` result in a variable and see the problems with `problems()`. – F. Privé Jul 14 '17 at 08:34