0

I am using biological data from an imported CSV file where the gene symbols are put into "column 0" as rownames. I would like to order the rows alphabetically based on gene symbol.

I was thinking of extracting the column 0 rownames to a new column and then ordering but I prefer leaving the dataset how it is. Is there anyway to order the row names instead?

learner123
  • 51
  • 5

1 Answers1

0
row_names_test <- data.frame(cbind(genes <- rownames(read.csv("~/row_names_test.csv")),
                                   read.csv("~/row_names_test.csv")))

row_names_test <- row_names_test[order(row_names_test$genes), ]
hello_friend
  • 5,682
  • 1
  • 11
  • 15
  • Thanks, I'll keep this in mind if I need the data this way later. For now I'm trying to keep the rownames in the original df. :) – learner123 Oct 15 '19 at 11:02
  • rownames(row_names_test) <- row_names_test$genes row_names_test <- within(row_names_test, rm("genes")) Please upvote / accept answer if you found it useful. – hello_friend Oct 15 '19 at 12:15
  • I have but my reputation is quite low so i don't know if it displays – learner123 Oct 15 '19 at 12:26