Re: [R] sorting dataframe

2012-10-03 Thread killerkarthick
Please show the data set... -- View this message in context: http://r.789695.n4.nabble.com/sorting-dataframe-tp840507p4644857.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list h

Re: [R] sorting dataframe by arbitrary order

2011-10-14 Thread Trevor Davies
Works great. I did a couple changes so as to not affect the original data.frame (and had to add levels back b/c I removed them in the original read.csv). a <- data.frame(V1=letters[rep(4:1,2)], V2=1001:1008) b <- a levels(b) <- unique(a$V1) b$V1 <- factor(b$V1,levels=c('c','d','a','b')) a.sorted

Re: [R] sorting dataframe by arbitrary order

2011-10-14 Thread William Dunlap
Set the levels of the factor a$V1 to the order in which you want them to be sorted. E.g., > a <- data.frame(V1=letters[rep(4:1,2)], V2=1001:1008) > a[do.call(order,a[c('V1','V2')]),] V1 V2 4 a 1004 8 a 1008 3 b 1003 7 b 1007 2 c 1002 6 c 1006 1 d 1001 5 d 1005

Re: [R] Sorting dataframe by number of occurrences of factor

2011-05-01 Thread adigs
That's great - thanks all for your help.-- View this message in context: http://r.789695.n4.nabble.com/Sorting-dataframe-by-number-of-occurrences-of-factor-tp3485443p3488978.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-proj

Re: [R] Sorting dataframe by number of occurrences of factor

2011-04-30 Thread Oliver
to the first two lines of your solutions df<-data.frame(id=c(1:20),name=c('a','b','b','c','a','d','b','e', 'd','d','c','a','b','a','a','b','f','b','c','g')) freq <- ave(rep(1, times=nrow(df)), df$name, FUN=sum) I would add: df[ sort.list(freq), ] __

Re: [R] Sorting dataframe by number of occurrences of factor

2011-04-30 Thread Sharma D
df<-data.frame(id=c(1:20),name=c('a','b','b','c','a','d','b','e','d','d','c','a','b','a','a','b','f','b','c','g')) freq <- ave(rep(1, times=nrow(df)), df$name, FUN=sum) rowSums(table(df$name,freq)) -- View this message in context: http://r.789695.n4.nabble.com/Sorting-dataframe-by-number-of-occ

Re: [R] Sorting dataframe by number of occurrences of factor

2011-04-30 Thread Petr Savicky
On Fri, Apr 29, 2011 at 11:17:58PM -0700, adigs wrote: > Apologies for what's probably quite simple, but I'm having some problems with > sorting a data frame by the number of occurences of each level of a factor. > > df<-data.frame(id=c(1:20),name=c('a','b','b','c','a','d','b','e','d','d','c','a',

Re: [R] sorting dataframe

2007-11-21 Thread Søren Højsgaard
- or the orderBy function in the doBy package. Soren From: [EMAIL PROTECTED] on behalf of Henrik Bengtsson Sent: Wed 21-11-2007 11:14 To: Rina Oldager Miehs Cc: r-help@r-project.org Subject: Re: [R] sorting dataframe See order(). -Henrik On 21/11/2007, Rina

Re: [R] sorting dataframe

2007-11-21 Thread Henrik Bengtsson
See order(). -Henrik On 21/11/2007, Rina Oldager Miehs <[EMAIL PROTECTED]> wrote: > Hello > > We have a problem with sorting our dataframe... > i have tried to write > > x <- males[sort(males$index, decreasing=T),] > > But that just gives me > > > x > id sex BVgain BVmeat phenogain phenomeat