Re: [R] sort

2020-05-15 Thread Rui Barradas
Hello, Here is a dplyr solution. arrange() sorts by name and desc(ddate) and top_n keeps the first 2 after grouping by ddate. Then it's a matter of being careful with diff() in the summarise instruction. library(dplyr) DF1 %>% mutate(ddate = as.Date(ddate)) %>% arrange(name, desc(ddate)

Re: [R] sort

2020-05-14 Thread Jim Lemon
Hi Val, Your problem is keeping the orders straight. You want dates decreasing and names increasing: DF1<-read.table(text="name ddate A 2019-10-28 A 2018-01-25 A 2020-01-12 A 2017-10-20 B 2020-11-20 B 2019-10-20 B 2017-05-20 B 2020-01-20 C 2009-10-01 ",header=TRUE) DF1$

Re: [R] sort()ing strings

2016-10-13 Thread peter dalgaard
> On 13 Oct 2016, at 13:00 , Martin Maechler wrote: > > which I do find strange, indeed, given your sessionInfo which > contains > LC_COLLATE=en_US.UTF-8 > One of the _really_ strange things about localization is that there is no standardization. Names don't necessarily mean the same th

Re: [R] sort()ing strings

2016-10-13 Thread Bob O'Hara
Thanks - strangely capabilities("ICU") is FALSE (I'm using ubuntu 16.04, and icu-devtools is installed). So I guess I'll conclude that there's something odd, but I don't want to delve into these issues (a new locale & new computer for me in a couple of months). Bob On 13 October 2016 at 13:00, Ma

Re: [R] sort()ing strings

2016-10-13 Thread Martin Maechler
> Bob O'Hara > on Thu, 13 Oct 2016 11:55:04 +0200 writes: > Yes, thanks. That seems to be it: > thing <- c("M1", "M2", "M.1", "M.2") >> sort(thing) > [1] "M1" "M.1" "M2" "M.2" which I do find strange, indeed, given your sessionInfo which contains LC_COLLATE=e

Re: [R] Sort data and symbol change in Jitter plot (ggplot2)

2015-05-06 Thread Luis Fernando García
Thanks all of you guys! Your answers were very useful! Thanks for the answer John, but I will try to keep the dotplot, but it is very useful to know both techniques anyway :) Petr, many thanks for your help, it was just what I needed, btw, the arrangment based on the median was a headache for me

Re: [R] Sort data and symbol change in Jitter plot (ggplot2)

2015-05-05 Thread PIKAL Petr
Hi answeres in line > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luis > Fernando García > Sent: Tuesday, May 05, 2015 9:34 AM > To: r-help@r-project.org > Subject: [R] Sort data and symbol change in Jitter plot (ggplot2) > > Dear R experts, > > Fi

Re: [R] sort adjacency matrix

2015-04-06 Thread David Winsemius
On Apr 6, 2015, at 11:15 AM, Bert Gunter wrote: > Not quite, David. > > If I understand the OP's query, he wants the ties to be broken by the > "lexicographic" order (with apologies if I have misused this term) of > the 1's within the rows. Makes things a bit more interesting. This should corre

Re: [R] sort adjacency matrix_with data

2015-04-06 Thread Ragia Ibrahim
6 Apr 2015 19:20:02 +0100 > From: ruipbarra...@sapo.pt > To: ragi...@hotmail.com; r-help@r-project.org > Subject: Re: [R] sort adjacency matrix > > Hello, > > You should have used ?dput to post your data example. > Since you haven't, I've made up one. > >

Re: [R] sort adjacency matrix

2015-04-06 Thread Rui Barradas
Hello, You should have used ?dput to post your data example. Since you haven't, I've made up one. set.seed(4795) mat <- matrix(sample(0:1, 24, replace = TRUE), nrow = 6) mat inx <- order(rowSums(mat), decreasing = TRUE) mat[inx, ] Hope this helps, Rui Barradas Em 06-04-2015 18:18, Ragia Ibr

Re: [R] sort adjacency matrix

2015-04-06 Thread Bert Gunter
Not quite, David. If I understand the OP's query, he wants the ties to be broken by the "lexicographic" order (with apologies if I have misused this term) of the 1's within the rows. Makes things a bit more interesting. Have at it! Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (6

Re: [R] sort adjacency matrix

2015-04-06 Thread David L Carlson
The answer depends on what kind of matrix/data frame you have. That is why we encourage people to use dput() to create a copy of the sample data in their email. Some combination of order() function the rowSums() function will probably get you what you want. For example, dat[order(rowSums(dat=="

Re: [R] sort by decreasing columns?

2014-12-13 Thread Jeff Newmiller
In general, different rows would sort in different orders. Your example does not illustrate how you would want to address such a problem. Here I assume you are only interested in sorting by the values in the first row. dta <- data.frame(a=c(2,3), b=c(3,5), c=c(8,9)) dta[,order(unlist(dta[1,]),de

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 order of a character sequence is different on windose and linux (linux result)

2014-07-08 Thread Witold E Wolski
>From my reading of http://r.789695.n4.nabble.com/internal-string-comparison-Scollate-td4687584.html they have good arguments to ask for Scollate whatever it is in the R public API. And from my point of view R would benefit from a tight integration of data.table. Without data.table R is very impr

Re: [R] sort order of a character sequence is different on windose and linux (linux result)

2014-07-06 Thread Duncan Murdoch
On 06/07/2014, 7:56 AM, Witold E Wolski wrote: > This is the info I got from the data.table developers... Seems that > they did have tried to find a more elegant solution solution.: >From my reading of the response below, data.table doesn't use R's sort() function to do their sorting. You should

Re: [R] sort order of a character sequence is different on windose and linux (linux result)

2014-07-06 Thread Witold E Wolski
This is the info I got from the data.table developers... Seems that they did have tried to find a more elegant solution solution.: data.table used to support this until 1.8.6. But since Scollate became not a part of authorised R-API (IIUC) anymore at some point, data.table only supports sort/orde

Re: [R] sort order of a character sequence is different on windose and linux (linux result)

2014-07-06 Thread Duncan Murdoch
On 06/07/2014, 7:19 AM, Witold E Wolski wrote: > It seems that the package I am developing depends on the locale "C" > because of interactions with other packages (data.table). > > So I would like to set the locale to "C" as soon as the package is loaded. > Where can I do it .. I could of course s

Re: [R] sort order of a character sequence is different on windose and linux (linux result)

2014-07-06 Thread Witold E Wolski
It seems that the package I am developing depends on the locale "C" because of interactions with other packages (data.table). So I would like to set the locale to "C" as soon as the package is loaded. Where can I do it .. I could of course set it in every function in my package but... ___

Re: [R] sort order of a character sequence is different on windose and linux (linux result)

2014-07-06 Thread Duncan Murdoch
On 06/07/2014, 6:30 AM, Witold E Wolski wrote: > This is the result of sorting a character sequence on a linux box > (with R . 3.10) See ?sort. The sort order depends on your locale. Set it to "C" for consistent ordering if that is important to you. For example, on my system: > "B" < "a" [1] F

Re: [R] sort() depends on locale (and platform and build)

2014-06-15 Thread Marius Hofert
Hi, ... so something like this? [in foo.R] old.coll <- Sys.getlocale("LC_COLLATE") Sys.setlocale("LC_COLLATE", locale="C") Sys.setlocale("LC_COLLATE", locale=old.coll) Cheers, Marius __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/

Re: [R] sort() depends on locale (and platform and build)

2014-06-15 Thread Prof Brian Ripley
On 15/06/2014 17:34, Marius Hofert wrote: Hi, Thanks for you help. I use R-devel under Ubuntu 14.04, here is the output of sessionInfo(): sessionInfo() R Under development (unstable) (2014-06-02 r65832) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_N

Re: [R] sort() depends on locale (and platform and build)

2014-06-15 Thread Marius Hofert
Hi, Thanks for you help. I use R-devel under Ubuntu 14.04, here is the output of sessionInfo(): > sessionInfo() R Under development (unstable) (2014-06-02 r65832) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_C

Re: [R] sort() depends on locale

2014-06-15 Thread Prof Brian Ripley
On 15/06/2014 12:16, Duncan Murdoch wrote: On 15/06/2014, 1:15 AM, Marius Hofert wrote: Hi, If I use invisible(Sys.setlocale("LC_COLLATE", "C")) in ~/.Rprofile, then sort(c("L.Y", "Lu", "L.Q")) [1] "L.Q" "L.Y" "Lu" whereas using invisible(Sys.setlocale("LC_COLLATE", "en_US.UTF-8")) results

Re: [R] sort() depends on locale

2014-06-15 Thread Duncan Murdoch
On 15/06/2014, 1:15 AM, Marius Hofert wrote: > Hi, > > If I use invisible(Sys.setlocale("LC_COLLATE", "C")) in ~/.Rprofile, then > >> sort(c("L.Y", "Lu", "L.Q")) > [1] "L.Q" "L.Y" "Lu" > > whereas using invisible(Sys.setlocale("LC_COLLATE", "en_US.UTF-8")) results in > >> sort(c("L.Y", "Lu", "L

Re: [R] sort() depends on locale (and platform and build)

2014-06-14 Thread Prof Brian Ripley
On 15/06/2014 07:45, Pascal Oettli wrote: Hello, Please provide your sessionInfo(). I don't see this issue with R 3.1.0 Patched on Linux. Nor on any of my platforms. We would also need to know if ICU was found when R was installed: see ?Comparison . Regards, Pascal On Sun, Jun 15, 2014

Re: [R] sort() depends on locale

2014-06-14 Thread Pascal Oettli
Hello, Please provide your sessionInfo(). I don't see this issue with R 3.1.0 Patched on Linux. Regards, Pascal On Sun, Jun 15, 2014 at 2:15 PM, Marius Hofert wrote: > Hi, > > If I use invisible(Sys.setlocale("LC_COLLATE", "C")) in ~/.Rprofile, then > >> sort(c("L.Y", "Lu", "L.Q")) > [1] "L.Q"

Re: [R] Sort data by month

2013-05-22 Thread arun
Regards, Arun   From: "zilefacel...@yahoo.com" To: arun Cc: R help Sent: Thursday, May 23, 2013 1:42 AM Subject: Re: Re: [R] Sort data by month Hi AK, Thanks so much. Problem well handled. Atem. -- Original Message -

Re: [R] Sort data by month

2013-05-22 Thread arun
ntical(datNew,datNew2) #[1] TRUE A.K. From: Zilefac Elvis To: arun Cc: R help Sent: Thursday, May 23, 2013 12:32 AM Subject: Re: [R] Sort data by month Hi Ak, I seems to work correctly with your data. Please try it on my data (attached). My data is month

Re: [R] Sort data by month

2013-05-22 Thread Zilefac Elvis
. From: arun To: Zilefac Elvis Cc: R help Sent: Wednesday, May 22, 2013 8:47 PM Subject: Re: [R] Sort data by month Hi, May be this helps. date1<-seq.Date(as.Date("01/01/2000",format="%d/%m/%Y"),as.Date("31/12/2010",format="%d/%m/%Y&q

Re: [R] Sort data by month

2013-05-22 Thread arun
Hi, May be this helps. date1<-seq.Date(as.Date("01/01/2000",format="%d/%m/%Y"),as.Date("31/12/2010",format="%d/%m/%Y"),by="day") set.seed(24)  value<- rnorm(4018,25)  dat1<- data.frame(date1,value)  dat2<- do.call(rbind,split(dat1,as.numeric(gsub(".*\\-(.*)\\-.*","\\1",dat1$date1 library(zoo

Re: [R] sort matrix based on a specific order

2013-01-10 Thread Ioannis Kosmidis
mat[match(ind, mat[, 2]), ] [,1] [,2] [1,] "y" "c" [2,] "x" "b" [3,] "z" "d" [4,] "w" "a" though you need to take care if you have cases where ind will contains letters that are not in mat[, 2] and so on (check ?match). Best, I On 10 Jan 2013, at 18:21, array chip wrote: > Hi I h

Re: [R] sort matrix based on a specific order

2013-01-10 Thread arun
HI, Try this:  mat[match(ind,mat[,2]),]   #   [,1] [,2] #[1,] "y"  "c" #[2,] "x"  "b" #[3,] "z"  "d" #[4,] "w"  "a" A.K. - Original Message - From: array chip To: "r-help@r-project.org" Cc: Sent: Thursday, January 10, 2013 1:21 PM Subject: [R] sort matrix based on a specific o

Re: [R] sort matrix based on a specific order

2013-01-10 Thread array chip
Thank you all for the suggestions, fantastic! From: Rui Barradas Cc: "r-help@r-project.org" Sent: Thursday, January 10, 2013 10:32 AM Subject: Re: [R] sort matrix based on a specific order Hello, Try the following. order() gives you a permutat

Re: [R] sort matrix based on a specific order

2013-01-10 Thread Rui Barradas
Hello, Try the following. order() gives you a permutation of the vector 'ind' and to order that permutation gives its inverse. mat <- cbind(c('w','x','y','z'),c('a','b','c','d')) ind <- c('c','b','d','a') ord <- order(ind) mat[order(ord), ] Hope this helps, Rui Barradas Em 10-01-2013 18:21,

Re: [R] sort matrix based on a specific order

2013-01-10 Thread jim holtman
more complete example > mat<-cbind(c('w','x','y','z'),c('a','b','c','d')) > matOrd <- mat[order(factor(mat[,2], levels = c('c', 'b', 'd','a'))), ] > matOrd [,1] [,2] [1,] "y" "c" [2,] "x" "b" [3,] "z" "d" [4,] "w" "a" > On Thu, Jan 10, 2013 at 1:21 PM, array chip wrote: > Hi I have a

Re: [R] sort matrix based on a specific order

2013-01-10 Thread William Dunlap
You can use factor() or match() to specify a particular order. E.g., > mat<-cbind(c('w','x','y','z'),c('a','b','c','d')) > ind<-c('c','b','d','a') > mat[ order(match(mat[,2], ind)), ] [,1] [,2] [1,] "y" "c" [2,] "x" "b" [3,] "z" "d" [4,] "w" "a" > mat[ order( factor(

Re: [R] sort matrix based on a specific order

2013-01-10 Thread jim holtman
Define them as factors with a specified order for your sorting. e.g. x <- factor(your_data, levels = c('c', 'b','d', 'a')) On Thu, Jan 10, 2013 at 1:21 PM, array chip wrote: > Hi I have a character matrix with 2 columns A and B, If I want to sort the > matrix based on the column B, but based

Re: [R] Sort or Permutate

2012-09-11 Thread arun
Hasselman To: Alaios Cc: R help Sent: Tuesday, September 11, 2012 11:00 AM Subject: Re: [R] Sort or Permutate On 11-09-2012, at 13:13, Alaios wrote: > Dear all, > I am having a struct that contains on the first column file names and on the > second column a number which is a "

Re: [R] Sort or Permutate

2012-09-11 Thread Bert Gunter
Ah, but note that the OP's 2nd column is character, not numeric... And we don't know what the "struct" is (a matrix or data frame?? --does the OP know the difference?). Has Alaios perused "An Introduction to R" where he/she might have gained some enlightenment that would have obviated the need to p

Re: [R] Sort or Permutate

2012-09-11 Thread Berend Hasselman
On 11-09-2012, at 13:13, Alaios wrote: > Dear all, > I am having a struct that contains on the first column file names and on the > second column a number which is a "rating" of the file on first column > > A small subset looks like that > > small > [,1]

Re: [R] Sort 1-column dataframe with rownames

2012-06-08 Thread arun
Hi, Try this, df.sort<-apply(df,2,sort) > df.sort    x A  1 D  2 I  2 B  3 J  8 G 12 H 33 E 34 F 44 C 51 df.sort<-as.data.frame(df.sort) A.K. - Original Message - From: Johannes Radinger To: R-help@r-project.org Cc: Sent: Friday, June 8, 2012 3:22 AM Subject: [R] Sort 1-column

Re: [R] Sort 1-column dataframe with rownames

2012-06-08 Thread Johannes Radinger
Hi Achim, thank you for your good explanation and the solution to my question... cheers, /j Original-Nachricht > Datum: Fri, 8 Jun 2012 09:30:42 +0200 (CEST) > Von: Achim Zeileis > An: Johannes Radinger > CC: R-help@r-project.org > Betreff: Re: [R] Sort 1-c

Re: [R] Sort 1-column dataframe with rownames

2012-06-08 Thread Ivan Calandra
Hi Johannes, You need to add the drop=FALSE argument in order to keep the structure: df.sort <- df[order(df[,"x"]), , drop=FALSE] ## don't forget the extra comma See ?"[" for details HTH, Ivan -- Ivan CALANDRA Université de Bourgogne UMR CNRS/uB 6282 Biogéosciences 6 Boulevard Gabriel 21000

Re: [R] Sort 1-column dataframe with rownames

2012-06-08 Thread Achim Zeileis
On Fri, 8 Jun 2012, Johannes Radinger wrote: Hi, I have a 1-column dataframe with rownames and I want to sort it based on the single column. The typical procedure that is recommended in diverse posts is to use order in the index. But that "destroys" my dataframe structure. Probabaly it is a ver

Re: [R] Sort across multiple csv

2012-05-18 Thread David Winsemius
On May 18, 2012, at 12:56 PM, Matthew Ouellette wrote: Dear R help list, I am very new to R and I apologize in advance if this has been answered before. I have done my best to google/R search what I need but no luck. Here is what I am attempting: I have hundreds of .csv files that I nee

Re: [R] Sort across multiple csv

2012-05-18 Thread Rui Barradas
Hello, Try the following. # Make some data alldata <- list(matrix(rnorm(12), ncol=3), matrix(sample(100), ncol=10)) (alldata <- lapply(alldata, function(x){colnames(x) <- c("Name", LETTERS[2:ncol(x)]); x})) # This does the trick all.order <- lapply(alldata, function(x) order(x[, "Name"])) lappl

Re: [R] Sort across multiple csv

2012-05-18 Thread MacQueen, Don
You appear to have a good start. If you type alldata[[1]] do you get what you expect for the first file? This is not tested, but I would start with something like this: sorteddata <- lapply(alldata, function(df) df[order(df$Name),] ) ## then this will overwrite for (id in seq(filenames)) {

Re: [R] Sort out number on value

2012-04-20 Thread R. Michael Weylandt
This really has little to do with sorting, but can be much more easily done with logical subscripting: x[x < 20] which I read as "x such that x is less than 20". Hope this helps, Michael On Fri, Apr 20, 2012 at 6:26 AM, Yellow wrote: > Can anyone help me maybe with a question I can seem to fin

Re: [R] Sort out number on value

2012-04-20 Thread Milan Bouchet-Valat
Le vendredi 20 avril 2012 à 03:26 -0700, Yellow a écrit : > Can anyone help me maybe with a question I can seem to find an answer on. > > I have this: x = c(1, 5, 70, 53, 7, 29, 75, 37, 30, 11) > > And I would like to have the numbers above 20 selected out. > But I can't find what code I need

Re: [R] sort list

2012-03-14 Thread sybil kennelly
O yea sure. So for example: grid <- read.table("table") ( i havent printed the output, as the table is 20,000 rows X 60 columns) point_of_interest <- c("row1", "row2") therefore all the other points in plot(table) are labelled green, but these two are labelled red. But at the minute, becaus

Re: [R] sort list

2012-03-14 Thread R. Michael Weylandt
Errr...I'm still not sure how plot(table) gives you read and green points, but it sounds like the easiest thing to do would be to use the points() function to come back in and put new green points over the red ones. E.g. plot(runif(5000), runif(5000)) points(c(0.5, 0.25), c(0.5, 0.75), col = 2, pc

Re: [R] sort list

2012-03-14 Thread R. Michael Weylandt
What sort of plot are you using? I'm not really clear on what your data as a whole look like: if you use dput() you can create a representation and we can work from there. In addition to the resources Josh recommended, the following sites can direct you to all sorts of graphical goodies, all of wh

Re: [R] sort list

2012-03-14 Thread sybil kennelly
I appreciate the reading Thank you. May i ask one final question. If i have: matrix: > var1var2 var3 > cell1x x x > cell2x x x > cell3x x x > > cell4 > > . > . > . > . > cell100 and: vector1 <- c("cell1, "cell5",cell19", "cell

Re: [R] sort list

2012-03-13 Thread sybil kennelly
Thanks Josh. I'm quite new, just wondering re:factor levels? In this example (shamelessly stolen from the internet): *schtyp* [1] 0 0 1 0 0 0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 *schtyp.f <- factor(schtyp, labels = c("private", "public")) schtyp.f* [1] private private public private private private p

Re: [R] sort list

2012-03-13 Thread Joshua Wiley
On Tue, Mar 13, 2012 at 5:15 AM, sybil kennelly wrote: > Thanks Josh. I'm quite new, just wondering re:factor levels? > > In this example (shamelessly stolen from the internet): > > schtyp > > [1] 0 0 1 0 0 0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 > > schtyp.f <- factor(schtyp, labels = c("private", "public"

Re: [R] sort list

2012-03-13 Thread Joshua Wiley
Hi Sybil, You cannot turn a list into a factor. You could do: cell_data <-c('cell1','cell2') factor_list <- factor(cell_data) or if you already have a list, unlist() or as.vector() may convert it into a vector that you can then convert to a factor. Cheers, Josh On Tue, Mar 13, 2012 at 4:29 A

Re: [R] sort dates

2012-03-09 Thread Gabor Grothendieck
On Fri, Mar 9, 2012 at 8:35 AM, carol white wrote: > Hello, > How is it possible to sort dates in R? > Your question has already been answered but note that if your data is a time series and you represent it using zoo it will automatically be sorted. Here dates is in reverse chronological order

Re: [R] sort dates

2012-03-09 Thread Robert Baer
How is it possible to sort dates in R? Try this: a = sample(as.Date(1:100, origin = '2012-01-01'),15) a [1] "2012-01-31" "2012-01-22" "2012-03-18" "2012-03-05" "2012-03-17" [6] "2012-03-08" "2012-01-08" "2012-01-20" "2012-03-01" "2012-03-21" [11] "2012-02-17" "2012-01-17" "2012-02-12" "2012-02

Re: [R] sort dates

2012-03-09 Thread Petr PIKAL
Hi > > Hello, > How is it possible to sort dates in R? You mean sort? Or order? Something like: > dd <-sample(Sys.Date()-1:10) > dd [1] "2012-03-04" "2012-03-05" "2012-02-29" "2012-03-01" "2012-03-02" [6] "2012-03-08" "2012-03-03" "2012-02-28" "2012-03-06" "2012-03-07" > sort(dd) [1] "2012-0

Re: [R] sort dates

2012-03-09 Thread R. Michael Weylandt
? sort x <- c(Sys.Date(), Sys.Date() + 1, Sys.Date() - 1) print(x) print(sort(x)) Michael On Fri, Mar 9, 2012 at 8:35 AM, carol white wrote: > Hello, > How is it possible to sort dates in R? > > Cheers, > > Carol > > __ > R-help@r-project.org mailin

Re: [R] sort() function for dates

2011-12-13 Thread David Winsemius
On Dec 13, 2011, at 3:43 AM, Ana wrote: Thanks people! another question, is there something similar to sort for dates? sort(x, decreasing = FALSE, ...) So what makes you even suspect that there wasn't a sort method for dates? -- David. On Tue, Dec 13, 2011 at 8:34 AM, Jorge I Velez >

Re: [R] sort a 3 dimensional array across third dimension ?

2011-02-18 Thread rex.dwyer
I was going to say: The problem with for-loops (as best I understand it) is that the R code gets interpreted over and over; what you normally want to do is design the computation so that you jump into the internals of R and stay there. But the inner loop is in the R internals of the sort in th

Re: [R] sort a 3 dimensional array across third dimension ?

2011-02-18 Thread jamaas
Thanks Claudia (and all others!0 This works beautifully! The instructions for aperm are a bit vauge! J -- View this message in context: http://r.789695.n4.nabble.com/sort-a-3-dimensional-array-across-third-dimension-tp3312612p3313126.html Sent from the R help mailing list archive at Nabble.co

Re: [R] sort a 3 dimensional array across third dimension ?

2011-02-18 Thread rex.dwyer
Although I suggested to someone else that for-loops be avoided, they are not in the inner loop in this code, and it's probably easier to understand than some sort of apply: a = array(round(100*runif(60)),dim=c(3,4,5)) a for (i in 1:dim(a)[1]) for (j in 1:dim(a)[2]) a[i,j,] = sort(a[i,j,]) a

Re: [R] sort a 3 dimensional array across third dimension ?

2011-02-18 Thread Maas James Dr (MED)
Hi Rex, Thanks, this is exactly what I want but have to do it with many big arrays ... thus if there were a way to do it with a vectorized function would it not be a lot more efficient? Much appreciated! J >Subject: RE: sort a 3 dimensional array across third dimension ? > >Although I suggest

Re: [R] sort a 3 dimensional array across third dimension ?

2011-02-18 Thread Claudia Beleites
Dear James, this is what I understood your sorting along the third dimension to be: > x <- array(c(9, 9, 7, 9, 6, 5, 4, 6, 2, 1, 3, 2), dim = list(2, 2, 3)) > y <- apply (x, 1:2, sort) > y , , 1 [,1] [,2] [1,]21 [2,]65 [3,]99 , , 2 [,1] [,2] [1,]32 [2

Re: [R] sort a 3 dimensional array across third dimension ?

2011-02-18 Thread Joshua Wiley
Dear Jim, This works for your small example. I was not exactly sure what you were sorting on. In my example, I sum all values at each level of the third dimension and sort by that sum. Of course, if there are many levels or the 2 dimensions being summed are quite large, this will be quite compu

Re: [R] sort by column and row names

2011-02-17 Thread Jim Moon
Yes, that is it. Thank you very much, Phil. -Original Message- From: Phil Spector [mailto:spec...@stat.berkeley.edu] Sent: Thursday, February 17, 2011 3:36 PM To: Jim Moon Cc: r-help@r-project.org Subject: Re: [R] sort by column and row names Jim - I believe dat[order(rownames

Re: [R] sort by column and row names

2011-02-17 Thread Phil Spector
Jim - I believe dat[order(rownames(dat)),order(colnames(dat))] is what you are looking for. - Phil Spector Statistical Computing Facility Department of Statistics

Re: [R] sort file names in numerical order

2010-07-18 Thread David Winsemius
Another option: require(gtools) ?mixedsort > mixedsort(fileNames) [1] "A1" "A2" "A10" "B1" "B2" "B10" -- David On Jul 18, 2010, at 5:16 AM, Duncan Mackay wrote: Hi Yes it is possible- one way is: fileNames[order(sprintf("%02s", sub("[[:upper:]]","", fileNames)))] [1] "A1" "B1" "A

Re: [R] sort file names in numerical order

2010-07-18 Thread Duncan Mackay
Hi Yes it is possible- one way is: fileNames[order(sprintf("%02s", sub("[[:upper:]]","", fileNames)))] [1] "A1" "B1" "A2" "B2" "A10" "B10" Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email home: mac...@northnet.com.au A

Re: [R] sort file names in numerical order

2010-07-17 Thread Michael Hannon
> I get some file names by list.files(). > These names are in alphabetical order. > I want to change it to logical numeric order. > Example: > > fileNames <- c("A10", "A1", "A2", "B1", "B2", "B10") > > sort(fileNames) > [1] "A1" "A10" "A2" "B1" "B10" "B2" > I want to have: > "A1" "A2" "A1

Re: [R] sort file names in numerical order

2010-07-17 Thread Sebastian Gibb
thanks a lot, it works. you wrote: > library(gtools) > ?mixedorder > > --- On Sat, 7/17/10, Sebastian Gibb wrote: > > From: Sebastian Gibb > > Subject: [R] sort file names in numerical order > > To: r-help@r-project.org > > Received: Saturday, July 17, 2010, 4:31 AM > > Hello, > > > > I get so

Re: [R] sort file names in numerical order

2010-07-17 Thread Gabor Grothendieck
On Sat, Jul 17, 2010 at 4:31 AM, Sebastian Gibb wrote: > Hello, > > I get some file names by list.files(). > These names are in alphabetical order. > I want to change it to logical numeric order. > Example: >> fileNames <- c("A10", "A1", "A2", "B1", "B2", "B10") >> sort(fileNames) > [1] "A1"  "A10

Re: [R] sort file names in numerical order

2010-07-17 Thread John Kane
library(gtools) ?mixedorder --- On Sat, 7/17/10, Sebastian Gibb wrote: > From: Sebastian Gibb > Subject: [R] sort file names in numerical order > To: r-help@r-project.org > Received: Saturday, July 17, 2010, 4:31 AM > Hello, > > I get some file names by list.files(). > These names are in al

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

Re: [R] sort the data set by one variable

2010-05-05 Thread Changbin Du
Yes, Phil! You are right, I forgot put the bo.id.pred$ ahead of predict. Thanks! On Wed, May 5, 2010 at 9:48 AM, Phil Spector wrote: > Changbin - > Perhaps you meant > > b.order = bo.id.pred[order(bo.id.pred$predict,decreasing=TRUE),] > >- Phil Spector

Re: [R] sort the data set by one variable

2010-05-05 Thread Changbin Du
Thanks Jim! I forgot the data$predict. Now it works for me too. Thanks so much! On Wed, May 5, 2010 at 9:36 AM, jim holtman wrote: > Works fine for me: > > > x > gene_idpredict > 43 637882902 0.07823997 > 53 638101634 0.66256490 > 61 639084581 0.08587504 > 41 637832824 0.02461066 > 25

Re: [R] sort the data set by one variable

2010-05-05 Thread jim holtman
Works fine for me: > x gene_idpredict 43 637882902 0.07823997 53 638101634 0.66256490 61 639084581 0.08587504 41 637832824 0.02461066 25 637261662 0.11613879 22 637240022 0.06350477 62 639084582 0.02238538 63 639097718 0.06792841 44 637943079 0.04532625 80 640158389 0.06582658 3 63700651

Re: [R] sort the data set by one variable

2010-05-05 Thread David Winsemius
On May 5, 2010, at 12:31 PM, Changbin Du wrote: #sort the data by predicted probability b.order<-bo.id.pred[(order(-predict)),] b.order[1:20,] gene_idpredict 43 637882902 0.07823997 53 638101634 0.66256490 61 639084581 0.08587504 41 637832824 0.02461066 25 637261662 0.11613879 22 63724

Re: [R] sort columns

2010-02-26 Thread Ista Zahn
Hi Frederik, Not exactly clear how you want them sorted, but one of these two is probably what you want: mat <- matrix(100:1, ncol=10) mat.1 <- apply(mat, 2, sort) mat.2 <- mat[order(10:1),] Best, Ista On Fri, Feb 26, 2010 at 12:41 PM, frederik vanhaelst wrote: > Hello, > > i have a 50*100 mat

Re: [R] sort columns

2010-02-26 Thread Henrique Dallazuanna
Try this: apply(m, 2, sort) On Fri, Feb 26, 2010 at 2:41 PM, frederik vanhaelst wrote: > Hello, > > i have a 50*100 matrix, with real numbers. How do i sort each column? > Now i sort it with a for-loop but this take a lot of time... > > Thank you, > > Frederik > >        [[alternative HTML versi

Re: [R] sort a data frame according to all the Columns

2010-01-27 Thread Erik Iverson
Erik Iverson wrote: I think you want ?order On second read, I think you want to do this without having to specify all 18 variables in an order call... something like this (with only 3 variables) v1 <- sample(rep(1:10, each = 2)) v2 <- sample(1:20) v3 <- sample(1:20) tmp <- data.frame(v1, v

Re: [R] sort a data frame according to all the Columns

2010-01-27 Thread Erik Iverson
I think you want ?order Juanjuan Chai wrote: Hi, I have a data frame read from a .csv file, with columns V1,V2,V3...,V18, per say, and I want to sort this data frame according to V1, and then V2, then V3..., and so on. Is there any fast way to get around with this problem? Thanks. -JJ _

Re: [R] Sort a data frame according to romans

2009-12-08 Thread Henrique Dallazuanna
Try this: mydata[order(as.roman(as.character(mydata$strata))),] On Tue, Dec 8, 2009 at 11:59 AM, Luis Ridao Cruz wrote: > R-help, > > I have a data frame: > >> mydata >   strata nh  Nh    Wh    fh > 1       I 10  26 0.048 0.385 > 2      II 32  84 0.154 0.381 > 3     III 16  42 0.077 0.381 > 4  

Re: [R] sort a data frame by a vector

2009-12-02 Thread Hao Cen
Thanks to all who replied. Issue solved Jeff On Wed, December 2, 2009 12:52 am, Don MacQueen wrote: > This looks like a job for match(). > > >> vec = c("C", "A", "B") >> >> dataDF = data.frame(A1 = c("B", "A", "C"), A2 = c(1,2,3)) >> >> >> dataDF[match(dataDF$A1,vec),] > A1 A2 > 3 C 3 > 2 A 2

Re: [R] sort a data frame by a vector

2009-12-01 Thread Don MacQueen
This looks like a job for match(). vec = c("C", "A", "B") dataDF = data.frame(A1 = c("B", "A", "C"), A2 = c(1,2,3)) dataDF[match(dataDF$A1,vec),] A1 A2 3 C 3 2 A 2 1 B 1 -Don At 10:36 PM -0500 12/1/09, Hao Cen wrote: Hi, I have a a vector and a data frame with two columns

Re: [R] sort a data frame by a vector

2009-12-01 Thread David Winsemius
On Dec 1, 2009, at 10:59 PM, jim holtman wrote: The factor statement should have been: (missed the 'vec' on the first reading) dataDF$A1 <- factor(dataDF$A1, levels=vec) It's not necessary to alter the data.frame. You can use the results of the construction above as the row index and st

Re: [R] sort a data frame by a vector

2009-12-01 Thread jim holtman
The factor statement should have been: (missed the 'vec' on the first reading) dataDF$A1 <- factor(dataDF$A1, levels=vec) On Tue, Dec 1, 2009 at 10:57 PM, jim holtman wrote: > Is this what you want: > >> dataDF = data.frame(A1 = c("B", "A", "C"), A2 = c(1,2,3)) >> dataDF >  A1 A2 > 1  B  1 > 2

Re: [R] sort a data frame by a vector

2009-12-01 Thread milton ruser
not ellegant.. but... vecDF = data.frame(A1=c("C", "A", "B")) vecDF$A1.order=1:dim(vecDF) vecDF dataDF = data.frame(A1 = c("B", "A", "C"), A2 = c(1,2,3)) dataDF2<-merge(vecDF, dataDF, by=intersect(colnames(vecDF),colnames(dataDF))) dataDF2 dataDF2.ord<-dataDF2[order(dataDF2$A1.order),] dataDF2.ord

Re: [R] sort a data frame by a vector

2009-12-01 Thread jim holtman
Is this what you want: > dataDF = data.frame(A1 = c("B", "A", "C"), A2 = c(1,2,3)) > dataDF A1 A2 1 B 1 2 A 2 3 C 3 > dataDF[order(dataDF$A1),] A1 A2 2 A 2 1 B 1 3 C 3 > If you want the sequence "CAB" then you will have to change the factors in column 1: > dataDF$A1 <- factor(dat

  1   2   >