Decreasing only numeric columns (more than one) in a dataframe with character and numeric column
1
0
Entering edit mode
4.2 years ago
camillab. ▴ 160

Hi,

I think it's a stupid question but I cannot find a way to do it online. I have post it on bioconductor as well (https://support.bioconductor.org/p/133467/) I want to sort simultaneously all the columns of my dataframe from the biggest to the smallest number (decreasing order) keeping at the same time the first column that contains the gene names (=characters) since I need to know which gene is what after the other columns has been re-ordered.

my dataset:

#A tibble: 3 x 12
  gene_symbol `control  0hr` `control 24hr`
  <chr>                <dbl>          <dbl>
1 5-8S                 270.           146. 
2 5S                   123.           129. 
3 7SK                   56.6           31.0

the only thing that works is selecting the numeric columns that I want to sort but in doing so I will lose the names of the genes:

CD.sorted <- apply(test[4:14],2,sort,decreasing=T)

if I run this the order is not decreasing and the number are all messed up (I got either all 0 or 9.99):

CD.sorted2 <- apply(test,2,sort,decreasing=T)

and if I run this code, the order is not decreased and all the number are again changed but I don't understand how:

library(dplyr)
f <- test %>% mutate_at(4:14, funs(sort(., decreasing = TRUE)))

and if I run this (where I tell exactly which columns to order) there is no changes at all:

CD.sorted2 <- arrange(test, desc("control  0hr", "control 24hr","control  48hr","control 54hr", "control 60hr","control 66hr","control 72hr","control 96hr","control 120hr" ,"control 144hr", "control 168hr" ))

thank you

Camilla

sort decreasing R RNA-Seq • 1.2k views
ADD COMMENT
0
Entering edit mode

This question belongs on biostars, not on bioC. However, your post there has more responses to it, which makes it confusing for people to follow. Please be more careful in the future - questions having to do with bioconductor packages go there, other bioinformatics questions go here.

ADD REPLY
0
Entering edit mode

oh ok. I did know. I realized after I posted on bioconductor. can I cancel one of the 2 post?

ADD REPLY
0
Entering edit mode

Don't worry about it now, once you get an answer that works, add an answer on the other post pointing to that answer.

ADD REPLY
1
Entering edit mode
4.2 years ago
Ram 44k

I've answered your question on bioC support. Please accept the answers both here and there using the green check mark on the left.

https://support.bioconductor.org/p/133467/#133480

ADD COMMENT

Login before adding your answer.

Traffic: 1494 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6