Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Duncan Murdoch
ere the pairwise comparison is obvious, while the numeric conversion isn't. A simple one would be a list of string vectors of different lengths, where you want to sort lexicographically. Duncan Have fun with the remainder of the advent! Another Martin From: R-help on behalf of Martin Møller Skar

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Martin Morgan
h for S3 generics), but rather define a class (e.g., that requires vectors person and value) and implement a corresponding `xtfrm()` method. Have fun with the remainder of the advent! Another Martin From: R-help on behalf of Martin Møller Skarbiniks Pedersen Date: Thursday, December 14, 2023

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
On Thu, 14 Dec 2023 at 12:02, Duncan Murdoch wrote: > > class(df$value) <- "sizeclass" > > `>.sizeclass` <- function(left, right) custom_sort(unclass(left), > unclass(right)) == 1 > > `==.sizeclass` <- function(left, right) custom_sort(unclass(left), > unclass(right)) == 0 > > `[.sizeclass` <- fu

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
> This sounds suspiciously like homework (which is off-topic... see the Posting > Guide) It is not homework. Currently I am trying to solve this: https://adventofcode.com/2023/day/7 But it is something that has puzzled me for a long time. In many programming languages, you can give a "less" func

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Duncan Murdoch
On 14/12/2023 3:00 a.m., Martin Møller Skarbiniks Pedersen wrote: Hi, I need to sort a data.frame based on a custom sorting function. It is easy in many languages but I can't find a way to do it in R. In many cases I could just use an ordered factor but my data.frame contains poker han

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Jeff Newmiller via R-help
This sounds suspiciously like homework (which is off-topic... see the Posting Guide), and you haven't indicated how you plan to encode your poker hands, and most core features of other languages are possible in R so if you really understand these other techniques and R then you should be able to

[R] Sorting based a custom sorting function

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
Hi, I need to sort a data.frame based on a custom sorting function. It is easy in many languages but I can't find a way to do it in R. In many cases I could just use an ordered factor but my data.frame contains poker hands and I need to rank these hands. I already got a function that compar

Re: [R] Sorting boxplots

2022-03-14 Thread Erich Subscriptions
f Fernando Archuby > Sent: Monday, March 14, 2022 12:13 PM > To: r-help@r-project.org > Subject: [R] Sorting boxplots > > [External Email] > > Dear all, > By default, boxplot() sorts boxes alphabetically. How can I avoid it or set > the order I need? > Thank you!

Re: [R] Sorting vector based on pairs of comparisons

2019-03-15 Thread Jim Lemon
Hi Bert, Good reference and David Urbina's example showed that a simple swap was position dependent. The reason I pursued this is that it seems more efficient to sequentially apply the precedence rules to the arbitrarily sorted elements of the vector than to go through the directed graph approach.

Re: [R] Sorting vector based on pairs of comparisons

2019-03-15 Thread Pedro Conte de Barros
Thanks Bert. Excellent reference, I learned a lot from it! Just a note: I did use search engines for at least 2 days before posting. BUT as often happens, I did not use the right keywords. I tried several variants of "Convert ordered pairs to sorted", "Sort vector on paired comparisons" and abo

Re: [R] Sorting vector based on pairs of comparisons

2019-03-15 Thread Bert Gunter
If I understand correctly, the answer is a topological sort. Here is an explanation https://davidurbina.blog/on-partial-order-total-order-and-the-topological-sort/ This was found by a simple web search on "Convert partial ordering to total ordering" Btw. Please use search engines before posting

Re: [R] Sorting vector based on pairs of comparisons

2019-03-14 Thread Jim Lemon
Hi Pedro, This looks too simple to me, but it seems to work: swap<-function(x,i1,i2) { tmp<-x[i1] x[i1]<-x[i2] x[i2]<-tmp return(x) } mpo<-function(x) { L<-unique(as.vector(x)) for(i in 1:nrow(x)) { i1<-which(L==x[i,1]) i2<-which(L==x[i,2]) if(i2 wrote: > > Dear All, > > This should be

Re: [R] Sorting vector based on pairs of comparisons

2019-03-14 Thread William Dunlap via R-help
This is called topological sorting in some circles. The function below will give you one ordering that is consistent with the contraints but not all possible orderings. I couldn't find such a function in core R so I wrote one a while back based on Kahn's algorithm, as described in Wikipedia. > S

Re: [R] Sorting vector based on pairs of comparisons

2019-03-14 Thread Pedro Conte de Barros
Thanks for this. Yes, this is checked before trying to process this. Pedro On 14/03/2019 14.09, Bert Gunter wrote: This cannot be done unless transitivity is guaranteed. Is it? S L a b b c c a Bert On Thu, Mar 14, 2019, 4:30 AM Pedro Conte de Barros mailto:pbar...@ualg.pt>> wrote: Dea

Re: [R] Sorting vector based on pairs of comparisons

2019-03-14 Thread Bert Gunter
This cannot be done unless transitivity is guaranteed. Is it? S L a b b c c a Bert On Thu, Mar 14, 2019, 4:30 AM Pedro Conte de Barros wrote: > Dear All, > > This should be a quite established algorithm, but I have been searching > for a couple days already without finding any satisfact

Re: [R] Sorting vector based on pairs of comparisons

2019-03-14 Thread Richard M. Heiberger
Try this. Anything that appears only in Smaller is candidate for smallest. Among those, order is arbitrary. Anything that appears only in Larger is a candidate for largest. Among those order is arbitrary. Remove rows of matComp containing the already classified items. Repeat with the smaller set

[R] Sorting vector based on pairs of comparisons

2019-03-14 Thread Pedro Conte de Barros
Dear All, This should be a quite established algorithm, but I have been searching for a couple days already without finding any satisfactory solution. I have a matrix defining pairs of Smaller-Larger arbitrary character values, like below Smaller <- c("ASD", "DFE", "ASD", "SDR", "EDF", "ASD")

Re: [R] Sorting of character vectors

2016-11-08 Thread Pascal A. Niklaus
Thanks for all suggestions. With my build (from the CRAN repo) I don't get ICU support, and setting LC_COLLATE to "C" did not help. > capabilities("ICU") ICU FALSE > sessionInfo() R version 3.3.2 (2016-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 14.04.5 LTS locale:

Re: [R] Sorting of character vectors

2016-11-08 Thread Rui Barradas
Hello, What is your sessionInfo()? With me it works as expected: > sort(c("-", "+")) [1] "-" "+" > sort(c("+", "-")) [1] "-" "+" > x5 <- c("+Aa","-Ab") > sort(x5) [1] "-Ab" "+Aa" > sessionInfo() R version 3.3.2 (2016-10-31) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64

Re: [R] Sorting of character vectors

2016-11-08 Thread peter dalgaard
On 08 Nov 2016, at 13:18 , Pascal A. Niklaus wrote: > I just got caught by the way in character vectors are sorted. > > It seems that on my machine "sort" (and related functions like "order") only > consider characters related to punctuation (at least here the "+" and "-") > when there is no

[R] Sorting of character vectors

2016-11-08 Thread Pascal A. Niklaus
I just got caught by the way in character vectors are sorted. It seems that on my machine "sort" (and related functions like "order") only consider characters related to punctuation (at least here the "+" and "-") when there is no difference in the remaining characters: > x1 <- c("-A","+A") >

Re: [R] sorting of files using system

2016-04-09 Thread Adrian Dușa
I suspect it is a problem related to locales: R and the base Ubuntu might be using different locales, hence the source of the different sorting. Can't say if this is the problem in your case, but it might be. Adrian On Sat, Apr 9, 2016 at 12:18 AM, Maria Ninova wrote: > Hello, I came across the

Re: [R] sorting of files using system

2016-04-08 Thread Jeff Newmiller
Wrong list. This is not the Ubuntu shell support mailing list. The fact that you are using R to get at the operating system command line doesn't make this an R question. -- Sent from my phone. Please excuse my brevity. On April 8, 2016 2:18:40 PM PDT, Maria Ninova wrote: >Hello, I came acros

[R] sorting of files using system

2016-04-08 Thread Maria Ninova
Hello, I came across the following oddity when it comes to file order using the system command: different system commands return files in a different order: This is a real filenames example: > system("ls gw1kb_tables/rpkm_47*", intern=T) [1] "gw1kb_tables/rpkm_479_Input.tab" [2] "gw1kb_tables/r

Re: [R] Sorting in trees problem

2016-02-24 Thread Bert Gunter
"%in%" is a wrapper for match(), which uses hashing I believe (correction welcome!),and so is generally very fast. See ?Rprof for profiling R code to get timings. (Haven't used it myself, so not sure how useful it would be for this situation). -- Bert Bert Gunter "The trouble with having an o

[R] Sorting in trees problem

2016-02-24 Thread Axel Urbiz
Hello, As decision trees require sorting the variable used for splitting a given node, I'm trying to avoid having this recurrent sorting by only sorting all numeric variable first (and only once). My attempt in doing this is shown in "Solution 2" below, but although I get the desired result I thi

Re: [R] sorting matrix by sets rows

2016-02-06 Thread Bert Gunter
?order is what I think you want. There is a slight wrinkle here, however. You want to sort Cluster in *increasing* order and Byers_EMT in *decreasing*, as I understand. order() will do both increasing, or both decreasing, but not differently. So a simple but inefficient way around this is to first

[R] sorting matrix by sets rows

2016-02-06 Thread Adrian Johnson
Hello: sorry I've been trying to sort a matrix to make waterfall plot using barplot function. I have have 30x5 matrix.Rows are samples and columns are results for a test as numeric vector. I want sort matrix by column. For example, first I want to sort column 1, in decreasing values where col

Re: [R] Sorting a Data Frame

2016-01-26 Thread Bert Gunter
... > mydf[2] # ??? B 1 4 2 5 3 6 A data frame is "really" a list of columns, so giving a single value returns that column. False. It returns a data frame consisting of a single column = a list containing a single component. mydf[[2]] returns a single component/column. While these differ

Re: [R] Sorting a Data Frame

2016-01-26 Thread Sarah Goslee
On Tue, Jan 26, 2016 at 4:24 PM, Robert Sherry wrote: > > Thank you for the response. As expected, the following expression worked: > df[order(df$x),] This says to sort the rows, and leave the columns alone. Subsetting a 2-dimensional object is via [rows, columns] > I would expect the follo

Re: [R] Sorting a Data Frame

2016-01-26 Thread Robert Sherry
Thank you for the response. As expected, the following expression worked: df[order(df$x),] I would expect the following expression to work also: df[order(df$x)] However it does not. That is, the comma is needed. Please tell me why the comma is there. Thanks Bob On 1/26/2016 8:19 A

Re: [R] Sorting a Data Frame

2016-01-26 Thread S Ellison
> On 23.01.2016 01:21, Robert Sherry wrote: > > In R, I run the following commands: > > df = data.frame( x=runif(10), y=runif(10) ) > > df2 = df[order(x),] > > > You use another x from your workspace, you actually want to > > > df2 = df[order(df[,"x"]),] or df[order(df$x),] And

Re: [R] Sorting a Data Frame

2016-01-22 Thread Uwe Ligges
On 23.01.2016 01:21, Robert Sherry wrote: In R, I run the following commands: df = data.frame( x=runif(10), y=runif(10) ) df2 = df[order(x),] You use another x from your workspace, you actually want to df2 = df[order(df[,"x"]),] Best, Uwe Ligges The first, as I would expect

[R] Sorting a Data Frame

2016-01-22 Thread Robert Sherry
In R, I run the following commands: df = data.frame( x=runif(10), y=runif(10) ) df2 = df[order(x),] The first, as I would expect, creates a data frame with two columns and 10 rows. I expect the second to sort the data based upon the columns x and produce a new data frame, df2, with the s

Re: [R] sorting a dataframe

2015-06-21 Thread Bogdan Tanasa
Thank you all again. It works with : library("gtools") dat[mixedorder(A),] considering : A = c("A1","A10","A11","A2") B = c(1,2,3,4) dat = data.frame(A,B On Sun, Jun 21, 2015 at 10:52 AM, Bert Gunter wrote: > Diego: > > Nonsense! Look at the results of your code -- you have failed to order

Re: [R] sorting a dataframe

2015-06-21 Thread Bert Gunter
Diego: Nonsense! Look at the results of your code -- you have failed to order the results as had been requested by the OP. It's also unnecessarily complicated. The following suffices (where I have used regular expressions rather substring() to get the numeric part of the strings -- **assuming** th

Re: [R] sorting a dataframe

2015-06-21 Thread Diego Miro
Bogdan, Follow my suggestion. letter <- substring(A, 1, 1) number <- substring(A, 2, nchar(A)) new.data <- paste0(letter, formatC(as.numeric(number), width = 2, flag = "0")) Em 20/06/2015 21:21, "Bogdan Tanasa" escreveu: > Dear all, > > I am looking for a suggestion please regarding sorting a d

Re: [R] sorting a dataframe

2015-06-20 Thread Bogdan Tanasa
thank you all, it is working fine. happy weekend ;) ! On Sat, Jun 20, 2015 at 6:15 PM, David Winsemius wrote: > > On Jun 20, 2015, at 5:18 PM, Bogdan Tanasa wrote: > > > Dear all, > > > > I am looking for a suggestion please regarding sorting a dataframe with > > alphanumerical components : > >

Re: [R] sorting a dataframe

2015-06-20 Thread David Winsemius
On Jun 20, 2015, at 5:18 PM, Bogdan Tanasa wrote: > Dear all, > > I am looking for a suggestion please regarding sorting a dataframe with > alphanumerical components : > > let's assume we have : > > A = c("A1","A10","A11","A2") > B = c(1,2,3,4) > > C = data.frame(A,B) > > how could I sort C

[R] sorting a dataframe

2015-06-20 Thread Bogdan Tanasa
Dear all, I am looking for a suggestion please regarding sorting a dataframe with alphanumerical components : let's assume we have : A = c("A1","A10","A11","A2") B = c(1,2,3,4) C = data.frame(A,B) how could I sort C data.frame in such a way that we have at the end : C$A in the order : "A1", "

Re: [R] sorting means for plot in descending order (Luis Fernando Garc?a)

2015-04-09 Thread Manel Amado Martí
To: r-help@r-project.org Subject: [R] sorting means for plot in descending order Message-ID: Content-Type: text/plain; charset="UTF-8" Dear R experts, I am newbie on the R use, now I want to sort my data by mean in a descending and not acending order (like I have done so far).

Re: [R] sorting means for plot in descending order

2015-04-09 Thread peter dalgaard
> On 09 Apr 2015, at 08:11 , Luis Fernando García wrote: > > Dear R experts, > > I am newbie on the R use, now I want to sort my data by mean in a > descending and not acending order (like I have done so far). If any of you > could help me with this, it would be really appreciated! How about

[R] sorting means for plot in descending order

2015-04-08 Thread Luis Fernando García
Dear R experts, I am newbie on the R use, now I want to sort my data by mean in a descending and not acending order (like I have done so far). If any of you could help me with this, it would be really appreciated! Thanks! Please find the script attached with the summary of the dat object pt<

Re: [R] Sorting list elements according to their mean value

2015-03-03 Thread William Dunlap
Use order(), as in sortListByMean <- function(List) { List[order(vapply(List, mean, 0))] } sortedL <- sortListByMean(l) Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 3, 2015 at 11:01 AM, wrote: > Hello R-helpers, > > I have a list of 999 dataframes and I would like to s

[R] Sorting list elements according to their mean value

2015-03-03 Thread mtb954
Hello R-helpers, I have a list of 999 dataframes and I would like to sort the list by the mean value of one of the columns in the data frames. Here is a small, self-contained example: #begin example iterations<-999 d<-list() #resampled data f<-list() #fitted values r<-list() #residuals l<-

Re: [R] Sorting data frame by prepared order

2015-03-02 Thread JS Huang
Here is an implementation. > t <- > data.frame(x=c(1,1,1,1,1,2,2,2,2,2),y=c("a","a","a","b","b","a","a","b","b","b")) > t x y 1 1 a 2 1 a 3 1 a 4 1 b 5 1 b 6 2 a 7 2 a 8 2 b 9 2 b 10 2 b > assignSeq function(test) { temp <- test[order(test$x),] InC <- numeric(length(test)) inD <-

Re: [R] Sorting data frame by prepared order

2015-03-02 Thread jeff6868
Hi, Maybe a beginning of solution with this? test <- data.frame(x=c(1,1,1,1,1,1,2,2,2,2,2,2),y=c("a","a","a","b","b","b","a","a","b","b","b","a")) test[order(test$x),] out <- split(test,test$x) for (i in 1:length(out)) { foo <- unique(out[[i]][,2]) out[[i]][,2] <- rep(foo,(nrow(out[[

Re: [R] Sorting Surv objects

2015-02-14 Thread Professor Bickis
Thanks for the quick response. My work-around was suggested as a quick fix for right-censored data, not as a general sort method for censored data. My concern was that sort does not work on right-censored data as described in the xtfrm documentation. Mik Bickis > On Feb 13, 2015, at 05:53 A

Re: [R] Sorting Surv objects

2015-02-13 Thread Therneau, Terry M., Ph.D.
Your work around is not as "easy" looking to me. Survival times come in multiple flavors: left censored, right censored, interval censored, left-truncated and right censored, and multi-state. Can you give me guidance on how each of these should sort? If a sort method is added to the package i

[R] Sorting Surv objects

2015-02-12 Thread Professor Bickis
It seems that Surv objects do not sort correctly. This seems to be a bug. Anyone else found this? >survival.data [1] 4+ 3 1+ 2 5+ >class(survival.data) [1] "Surv" >sort(survival.data) [1] 2 1+ 4+ 3 5+ An easy work-around is to define a function sort.Surv >sort.Surv<-function(a){ord<-orde

Re: [R] Sorting Surv objects

2015-02-12 Thread Prof Brian Ripley
On 12/02/2015 16:26, Professor Bickis wrote: It seems that Surv objects do not sort correctly. This seems to be a bug. Anyone else found this? This is presumably about Surv() from package survival, not mentioned. There was a bug, corrected in R-devel (and I will port to R-patched before 3.

[R] Sorting Surv objects

2015-02-12 Thread Professor Bickis
It seems that Surv objects do not sort correctly. This seems to be a bug. Anyone else found this? > survival.data [1] 4+ 3 1+ 2 5+ > class(survival.data) [1] "Surv" > sort(survival.data) [1] 2 1+ 4+ 3 5+ An easy work-around is to define a function sort.Surv sort.Surv<-function(a){ord<-or

Re: [R] Sorting method used by order()

2014-12-02 Thread Prof Brian Ripley
ument in order. For sort list, the default method is "radix", AFAIK. Cheers Petr -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Pierrick Bruneau Sent: Tuesday, December 02, 2014 12:33 PM To: r-h...@stat.math.ethz.ch Subject: [R] Sorting me

Re: [R] Sorting method used by order()

2014-12-02 Thread Duncan Murdoch
e default method is "radix", AFAIK. >> >> Cheers >> Petr >> >>> -Original Message- >>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of >>> Pierrick Bruneau >>> Sent: Tuesday, December 02, 2014 12:33 PM >>>

Re: [R] Sorting method used by order()

2014-12-02 Thread Pierrick Bruneau
ment in order. > > For sort list, the default method is "radix", AFAIK. > > Cheers > Petr > > > -Original Message- > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of > > Pierrick Bruneau > > Sent: Tuesday, December 02, 20

Re: [R] Sorting method used by order()

2014-12-02 Thread PIKAL Petr
rick Bruneau > Sent: Tuesday, December 02, 2014 12:33 PM > To: r-h...@stat.math.ethz.ch > Subject: [R] Sorting method used by order() > > Hi all, > > In ?order, the sorting method used appears as the "method" argument to > sort.list(), but I cannot make out which

[R] Sorting method used by order()

2014-12-02 Thread Pierrick Bruneau
Hi all, In ?order, the sorting method used appears as the "method" argument to sort.list(), but I cannot make out which is used by default when calling order(), and how to parametrize it. Does someone have a clue there? Thanks by advance, Pierrick [[alternative HTML version deleted]] _

Re: [R] Sorting within a dataframe Thank you

2014-10-31 Thread dodie
Thank you. Original Message Subject: Re: Sorting within a dataframe From: "jfzeac [via R]" < ml-node+s789695n4699000...@n4.nabble.com > Date: Thu, October 30, 2014 8:57 am To: dodie < do...@statcourse.com > Hi, a = data[order(data$x),] If you reply to this email, yo

Re: [R] Sorting data.frame datewise in a descending order and geting datewise subtotl

2014-07-03 Thread arun
Hi, Try: res1 <- aggregate(PROFIT~DATE, data=dat, FUN=sum) res1[rev(order(as.Date(res1$DATE, format="%d/%m/%Y"))),] #    DATE PROFIT #2 02/07/2014  -1350 #1 01/07/2014   9400 #4 30/06/2014  11325 #3 27/06/2014   6850 #if you don't wanted another column in the original dataset with `sum`  re

Re: [R] Sorting data.frame datewise in a descending order and geting datewise subtotl

2014-07-03 Thread veepsirtt
Hi A.K I modified and got the results thanks A.K library(XML) URL <- " http://money.securebank.in/index.php?option=com_dashboard&view=history&Itemid=56&startdate=01/01/2014&enddate=02/07/2014&exchange=MCX&sid=1 " doc <- htmlParse(URL) tableNodes <- getNodeSet(doc, "//table") l=length(tableNodes)

Re: [R] Sorting data.frame datewise in a descending order and geting datewise subtotl

2014-07-03 Thread veepsirtt
Warning in install.packages : package ‘dplyr’ is not available (for R version 2.15.3) Is there any alternate way to sorting data.frame datewise in a descending order?.(not using dplyr) On Thu, Jul 3, 2014 at 12:48 PM, Velappan Periasamy wrote: > Hi A.K > I modified and got the result

Re: [R] Sorting data.frame datewise in a descending order and geting datewise subtotl

2014-07-03 Thread veepsirtt
Hi A.K - library(XML) URL <- " http://money.securebank.in/index.php?option=com_dashboard&view=history&Itemid=56&startdate=01/01/2013&enddate=6/9/2014&exchange=MCX&sid=1"; doc <- htmlParse(URL) tableNodes <- getNodeSet(doc, "//table") dat1 <- readHTMLTable(tableNodes[[

Re: [R] Sorting data.frame datewise in a descending order and geting datewise subtotl

2014-07-02 Thread arun
Hi veepsirtt, If `dat` is the dataset library(dplyr)  dat %>% group_by(DATE) %>% summarize(PROFIT=sum(PROFIT)) %>%  arrange(desc(as.Date(DATE,format="%d/%m/%Y"))) Source: local data frame [4 x 2]     DATE PROFIT 1 02/07/2014  -1350 2 01/07/2014   9400 3 30/06/2014  11325 4 27/06/2014  

Re: [R] Sorting Data Frames in R by multiple columns with a custom order

2013-11-07 Thread arun
If you already have the order stored in a list or so: For example: dat1 <- as.data.frame(mat,stringsAsFactors=FALSE) lst1 <- list(c("OF","ON"), c("US","UK", "WW","BO","BR","CA"), c("P2","P3","P1"),c("S2","S1","S3"))  dat1[] <- lapply(seq_along(lst1),function(i) factor(dat1[,i],levels=lst1[[i]]))

Re: [R] Sorting Data Frames in R by multiple columns with a custom order

2013-11-07 Thread arun
Hi, Not sure whether this helps: dat1 <- as.data.frame(mat,stringsAsFactors=FALSE) dat1$c4 <- factor(dat1$c4,levels=c("OF","ON"))  dat1$c1 <- factor(dat1$c1,levels=c("US","UK","WW","BO","BR","CA"))  dat1$c2 <- factor(dat1$c2, levels=c("P2","P3","P1"))  dat1$c3 <- factor(dat1$c3, levels=c("S2","S1"

Re: [R] Sorting data

2013-08-26 Thread arun
Hi, Hope this is what you meant.. with(dat1,mean(V21[(V2==1|V2==0) & V24<25],na.rm=TRUE))  #[1] 2.8125  sapply(0:1,function(i) with(dat1,mean(V21[V2==i & V24<25],na.rm=TRUE))) #[1] 2.75 3.00 ". who are in condition 1 or 0 (V2) and then vice versa ..."  dat1[,21] # [1]   NA 3.40 3.00 3

Re: [R] Sorting data

2013-08-25 Thread arun
Hi, It's not clear what you really wanted.  May be this helps: dat1<- read.table(text="   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20   V21 V22 V23 V24 V25 V26 1 1  1  3  1 NA NA  1 NA NA   1   2   7   5   3   2 1.0  15  17   5   1    NA   1   2  19   1   1 2

Re: [R] Sorting data.frame and again sorting within data.frame

2013-04-16 Thread Katherine Gobin
Dear Sir, Thanks a lot for your valuable input and guidance. Regards Katherine --- On Mon, 15/4/13, Jeff Newmiller wrote: From: Jeff Newmiller Subject: Re: [R] Sorting data.frame and again sorting within data.frame To: "David Winsemius" , "Katherine Gobin" Cc: r-hel

Re: [R] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread David Winsemius
On Apr 15, 2013, at 9:33 AM, Jeff Newmiller wrote: > Yes, that would be because she converted to Date on the fly in her example, > and so apparently did not need this reminder. I apologize, Iobviously missed that. So the answer was simply to put a minus sign in front of the as.Date() expressi

Re: [R] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread Jeff Newmiller
Yes, that would be because she converted to Date on the fly in her example, and so apparently did not need this reminder. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#

Re: [R] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread David Winsemius
On Apr 14, 2013, at 11:01 PM, Katherine Gobin wrote: > Dear R forum, > > I have a data.frame as defied below - > > df = data.frame(names = c("C", "A", "A", "B", "C", "B", "A", "B", "C"), dates > = c("4/15/2013", "4/13/2013", "4/15/2013", "4/13/2013", "4/13/2013", > "4/15/2013", "4/14/2013",

Re: [R] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread arun
/2013 29 #5 C 4/13/2013 11 A.K. - Original Message - From: arun To: Katherine Gobin Cc: R help Sent: Monday, April 15, 2013 8:57 AM Subject: Re: [R] Sorting data.frame and again sorting within data.frame library(plyr) arrange(df,names,desc(dates)) #  names dates values #1

Re: [R] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread arun
/2013 11 A.K. - Original Message - From: Katherine Gobin To: r-help@r-project.org Cc: Sent: Monday, April 15, 2013 2:01 AM Subject: [R] Sorting data.frame and again sorting within data.frame Dear R forum, I have a data.frame as defied below - df = data.frame(names = c("C"

Re: [R] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread Jeff Newmiller
The examples in ?order show a method that could be applied if you avoid the decreasing argument and instead convert the Date to numeric for purposes of sorting. --- Jeff NewmillerThe . ..

[R] Sorting data.frame and again sorting within data.frame

2013-04-14 Thread Katherine Gobin
Dear R forum, I have a data.frame as defied below - df = data.frame(names = c("C", "A", "A", "B", "C", "B", "A", "B", "C"), dates = c("4/15/2013", "4/13/2013", "4/15/2013", "4/13/2013", "4/13/2013", "4/15/2013", "4/14/2013", "4/14/2013","4/14/2013" ),values = c(10, 31, 31, 17, 11, 34, 102, 47

Re: [R] sorting the VAR model output according to variable names??

2013-04-10 Thread Pfaff, Bernhard Dr.
, Bernhard -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von londonphd Gesendet: Dienstag, 9. April 2013 16:59 An: r-help@r-project.org Betreff: [R] sorting the VAR model output according to variable names?? I was wondering if on

[R] sorting the VAR model output according to variable names??

2013-04-09 Thread londonphd
I was wondering if one can have the coefficients of VAR model sorted according to variable names rather than lags. If you notice below, the output is sorted according to lags. >VAR(cbind(fossil,labour),p=2,type="const") VAR Estimation Results: === Estimated coefficients for

Re: [R] sorting/grouping/classification problem?

2013-01-28 Thread Bart Joosen
Hi, after all, brute force seems the way to go. I will use a simplified example to illustrate what I want (dump of dat4 is below): suppose dat4: ID rrt Mnd Result 1 0.45 00.1 1 0.48 00.3 1 1.24 00.5 2 0.45 30.2 2 0.48 30.6 2 1.22 30.4 I want to ge

Re: [R] sorting/grouping/classification problem?

2013-01-25 Thread arun
old 0.3 0.6 1.20 1.80 #4 1.2225    old 0.5 0.4 0.45 0.50 A.K. - Original Message - From: Bart Joosen To: Dennis Murphy ; r-help@r-project.org Cc: Sent: Friday, January 25, 2013 1:48 AM Subject: Re: [R] sorting/grouping/classification problem? Nice suggestion for the extra "Time" column

Re: [R] sorting/grouping/classification problem?

2013-01-25 Thread Bart Joosen
y possible combination of shuffling within certain limits (eg max 10% or so), calculate r2 for each combination and maximize? Seems so brute force and low elegant? Bart > Date: Fri, 25 Jan 2013 10:01:44 -0800 > From: smartpink...@yahoo.com > Subject: Re: [R] sorting/grouping/classific

Re: [R] sorting/grouping/classification problem?

2013-01-24 Thread Bart Joosen
clear now. Thank you all for your suggestions Bart > Date: Thu, 24 Jan 2013 15:01:40 -0800 > Subject: Re: [R] sorting/grouping/classification problem? > From: djmu...@gmail.com > To: bartjoo...@hotmail.com > > Hi: > > Here's a potential workaround: > > # Add

Re: [R] sorting/grouping/classification problem?

2013-01-24 Thread Bart Joosen
dat3 is the dataframe where there are some rrt values merged, which is actually the problem: how on Earth discide which rows van be merged Thanks for your input! Bart -Original Message- From: arun Sent: 24 Jan 2013 20:18:28 GMT To: Bart Joosen Cc: R help Subject: Re: [R] sorting

Re: [R] sorting/grouping/classification problem?

2013-01-24 Thread arun
.2   NA 0.60 #5 0.46  NA  NA 1.20   NA #6 0.48 0.3 0.6   NA 1.80 #7 1.21  NA  NA 0.45   NA #8 1.22  NA 0.4   NA 0.50 #9 1.24 0.5  NA   NA   NA A.K. - Original Message - From: Bart Joosen To: r-help Cc: Sent: Thursday, January 24, 2013 2:31 PM Subject: [R] sorting/grouping/classifi

[R] sorting/grouping/classification problem?

2013-01-24 Thread Bart Joosen
Hi, I'm a database admin for a database which manage chromatographic results of products during stability studies. I use R for the reporting of the results in MS Word through R2wd. But now I think I need your help: suppose we have the following data frame: ID rrt Mnd Result 1 0.45 0

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread Sarah Goslee
Spring 0.1927715 > #16 Spring 0.1927715 > > The process you describe does not get me there > > Any other recommendations? > > -Original Message- > From: arun [mailto:smartpink...@yahoo.com] > Sent: Thursday, October 11, 2012 10:33 AM > To: ROLL Josh F > Cc: R help >

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread arun
ly, the Obs column has only 4 values.  Do you want to get the means??? A.K. - Original Message - From: ROLL Josh F To: 'arun' Cc: R help Sent: Thursday, October 11, 2012 1:42 PM Subject: RE: [R] Sorting a data frame by specifying a vector Sorry if I wasn't clear but th

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread Bert Gunter
Winter 0.9318599 > #10 Winter 0.9318599 > #14 Winter 0.9318599 > #4 Spring 0.1927715 > #8 Spring 0.1927715 > #12 Spring 0.1927715 > #16 Spring 0.1927715 > > Any other thoughts? > > JR > > > -Original Message- > From: Bert Gunter [mailto:gunter.ber

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread ROLL Josh F
tober 11, 2012 10:33 AM To: ROLL Josh F Cc: R help Subject: Re: [R] Sorting a data frame by specifying a vector Hi, In your dataset, it seems like it is already ordered in the way you wanted to. df.. <- data.frame(Season=rep(c("Summer","Fall","Winter","Spring&

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread arun
927715 #5  Summer 0.2141001 #6  Winter 0.9318599 #7    Fall 0.6722337 #8  Spring 0.1927715 #9  Summer 0.2141001 #10 Winter 0.9318599 #11   Fall 0.6722337 #12 Spring 0.1927715 #13 Summer 0.2141001 #14 Winter 0.9318599 #15   Fall 0.6722337 #16 Spring 0.1927715 A.K. - Original Message - F

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread Bert Gunter
?order df[order(yourcolumn, ] -- Bert On Thu, Oct 11, 2012 at 10:08 AM, LCOG1 wrote: > Hello all, >I cannot seem to figure out this seemingly simple procedure. > > I want to sort a data frame by a specified character vector. > > So for : > > df.. <- data.frame(Season=rep(c("Summer","Fall","

[R] Sorting a data frame by specifying a vector

2012-10-11 Thread LCOG1
Hello all, I cannot seem to figure out this seemingly simple procedure. I want to sort a data frame by a specified character vector. So for : df.. <- data.frame(Season=rep(c("Summer","Fall","Winter","Spring"),4),Obs= runif(length(rep(c("Summer","Fall","Winter","Spring"),4 I want to so

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 of columns of a matrix

2012-08-29 Thread arun
--- From: Nico Met To: r-help@r-project.org Cc: Sent: Wednesday, August 29, 2012 9:24 AM Subject: [R] Sorting of columns of a matrix Dear all, Please suggest me how can I do it. I have a matrix which look like following:   x1 x2 x3  t1 .01 0.3 0  t2 0 0.1 0.01  t3 0 .01 .01  t4 0 0  t5 5 0 0 

Re: [R] Sorting of columns of a matrix

2012-08-29 Thread arun
-1.4130988 A.K. - Original Message - From: Nico Met To: r-help@r-project.org Cc: Sent: Wednesday, August 29, 2012 9:24 AM Subject: [R] Sorting of columns of a matrix Dear all, Please suggest me how can I do it. I have a matrix which look like following:   x1 x2 x3  t1 .01 0.3 0  t2 0 0.

Re: [R] Sorting of columns of a matrix

2012-08-29 Thread Nico Met
Met [mailto:nicome...@gmail.com] > *Sent:* Wednesday, August 29, 2012 4:56 PM > *To:* PIKAL Petr > > *Subject:* Re: [R] Sorting of columns of a matrix > > ** ** > > Thanks a lot. > > ** ** > > But I also want to attach row names (if avai

Re: [R] Sorting of columns of a matrix

2012-08-29 Thread PIKAL Petr
Hi > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Nico Met > Sent: Wednesday, August 29, 2012 4:25 PM > To: Berend Hasselman > Cc: r-help@r-project.org > Subject: Re: [R] Sorting of columns of a matrix

Re: [R] Sorting of columns of a matrix

2012-08-29 Thread PIKAL Petr
Hi From: Nico Met [mailto:nicome...@gmail.com] Sent: Wednesday, August 29, 2012 5:27 PM To: PIKAL Petr Cc: r-help Subject: Re: [R] Sorting of columns of a matrix Yes, each column shall have different sequence of row names And what? I do not understand? You still did not describe how do you

Re: [R] Sorting of columns of a matrix

2012-08-29 Thread PIKAL Petr
Met [mailto:nicome...@gmail.com] Sent: Wednesday, August 29, 2012 4:56 PM To: PIKAL Petr Subject: Re: [R] Sorting of columns of a matrix Thanks a lot. But I also want to attach row names (if available) associated with each column. In that case does your second code works in the same way? thanks

Re: [R] Sorting of columns of a matrix

2012-08-29 Thread Nico Met
Please find the require info: set.seed(12345) X<-matrix(rnorm(5*10),nrow=5) dim(X) X [,1] [,2][,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1.2774431 -1.2427735 0.81933548 -2.1098586 -1.6726799 -2.2994684 -0.28823228 0.192930

Re: [R] Sorting of columns of a matrix

2012-08-29 Thread Berend Hasselman
On 29-08-2012, at 16:08, Nico Met wrote: > Hello john, > > thanks for the suggestion. Please find an example: > >> X<-matrix(rnorm(5*10),nrow=5) > >> dim(X) > [1] 5 10 >> X > [,1] [,2][,3] [,4] [,5] [,6] > [,7] [,8] [,9] [,10] > [1,

  1   2   3   4   >