Re: [R] sort a data.frame in a different way

2014-10-22 Thread Sven E. Templer
seems like a transpose, so use ?t t(your.data.frame) On 22 October 2014 11:34, Matthias Weber wrote: > Hello together, > > i have a little problem. Maybe anyone can help me. > > I have a data. frame which look like this one: > 1000 1001 10021003 > 15 6 12

Re: [R] sort a data.frame

2010-05-21 Thread Kevin Wright
rame >>> dd <- data.frame(b = c("chr2", "chr1", "chrY", "chr13", "chrX"), >>>     x = c("A", "D", "A", "C", "C"), y = c(8, 3, 9, 9,7), >>>      z = c(1, 1, 1, 2, 8)

Re: [R] sort a data.frame

2010-05-21 Thread David Winsemius
he column b consists of not only number but also one letter after "chr", for example chrX, chrY. I want to put them after number but in the order of ASCII. i.e. chr1--- On *Thu, 20/5/10, Jorge Ivan Velez * wrote: From: Jorge Ivan Velez Subject: Re: [R] sort a data.frame To: &quo

Re: [R] sort a data.frame

2010-05-20 Thread Yuan Jian
it's a excellent solution. I am sorry I missed something in my question. the column b consists of not only number but also one letter after "chr", for example chrX, chrY. I want to put them after number but in the order of ASCII. i.e. chr1 wrote: From: Jorge Ivan Velez Subject:

Re: [R] sort a data.frame

2010-05-20 Thread Jorge Ivan Velez
ot;), > x = c("A", "D", "A", "C", "C"), y = c(8, 3, 9, 9,7), >z = c(1, 1, 1, 2, 8)) > > the expected result > >b x y z > 1 chr1 D 3 1 > 2 chr2 A 8 1 > 3 chr13 C 9 2 > 4 chrX C 7 8 > 5 chrY

Re: [R] sort a data.frame

2010-05-20 Thread Dejian Zhao
If you want to sort the data frame according to column "b", the followding code does this work. attach(dd) dd<-dd[order(b),] detach(dd) If you want to sort the data frame according to the chr number in column b, you should extract the numbers first into a vector, say chrnum, and then use order

Re: [R] sort a data.frame

2010-05-20 Thread Jorge Ivan Velez
Hi Yuan, Try dd[order(as.numeric(gsub("[^0-9]", "", dd$b))), ] HTH, Jorge On Thu, May 20, 2010 at 8:28 AM, Yuan Jian <> wrote: > Hello, > > I have a dataframe: > dd <- data.frame(b = c("chr2", "chr1", "chr15", "chr13"), > x = c("A", "D", "A", "C"), y = c(8, 3, 9, 9), >z = c(1, 1,

Re: [R] sort a data.frame

2010-05-20 Thread Mohamed Lajnef
The solution given by Jim is more correct dd[order(as.numeric(substr(dd$b,4,5))),] regards M jim holtman a écrit : dd b x y z 1 chr2 A 8 1 2 chr1 D 3 1 3 chr15 A 9 1 4 chr13 C 9 2 # add column with just numbers dd$sort <- as.integer(gsub("\\D+", "", dd$b)) dd[order(dd$sort),]

Re: [R] sort a data.frame

2010-05-20 Thread Nikhil Kaza
Try this. dd[order(gsub("chr","",dd$b)),] You need regular expressions if chr is not the only characterstring that is prepended to the numbers. look for ?strsplit Nikhil Kaza University of North Carolina nikhil.l...@gmail.com On May 20, 2010, at 8:28 AM, Yuan Jian wrote: Hello, I have

Re: [R] sort a data.frame

2010-05-20 Thread jim holtman
> dd b x y z 1 chr2 A 8 1 2 chr1 D 3 1 3 chr15 A 9 1 4 chr13 C 9 2 > # add column with just numbers > dd$sort <- as.integer(gsub("\\D+", "", dd$b)) > dd[order(dd$sort),] # notice it is a numeric, not character order b x y z sort 2 chr1 D 3 11 1 chr2 A 8 12 4 chr13 C 9 2 1