Re: [R] Ordering data by variable
On Thu, Sep 2, 2010 at 2:33 PM, Greg Snow wrote: > Suggestion: use the power of R. > > If x and y are independent then sorting y based on x is meaningless. > > If sorting y based on x is meaningful, then they are not independent. > > Trying to force non-independent things to pretend that they are independent > just causes future headaches. > > Part of the great power of R is the ability to group things together that > should be grouped. The wise learn this and use it (in some cases (mine) that > wisdom comes at the expense of not having properly grouped in the past). Yes, this is an excellent suggestion. My workspace used to be like a rock pile that my poor brain had to dig through, trying to remember some truly awful combinations of capitalizations, '.' , '_' , and numerals from my vain efforts to organize variables. Dataframes (and lists for those pesky variables with irregular lengths) were the rake that brought peace and tranquility to the rock garden of my workspace. Josh > Learn the power of with/within, data= arguments, and apply style functions, > then you will be eager to combine things into data frames (or lists or ...) > when appropriate. > > <> > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Center > Intermountain Healthcare > greg.s...@imail.org > 801.408.8111 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ordering data by variable
Suggestion: use the power of R. If x and y are independent then sorting y based on x is meaningless. If sorting y based on x is meaningful, then they are not independent. Trying to force non-independent things to pretend that they are independent just causes future headaches. Part of the great power of R is the ability to group things together that should be grouped. The wise learn this and use it (in some cases (mine) that wisdom comes at the expense of not having properly grouped in the past). Learn the power of with/within, data= arguments, and apply style functions, then you will be eager to combine things into data frames (or lists or ...) when appropriate. <> -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Mestat > Sent: Thursday, September 02, 2010 2:49 PM > To: r-help@r-project.org > Subject: [R] Ordering data by variable > > > Hi listers, > I could order a data that like this: > x<-c(2,6,8,8,1) > y<-c(1,6,3,5,4) > o<-order(x) > frame<-rbind(x,y)[,o] > But, I would like to know if there is a way to order my data without > setting > up a data frame. I would like to keep independent vectors x and y. > Any suggestions? > Thanks in advance, > Marcio > -- > View this message in context: http://r.789695.n4.nabble.com/Ordering- > data-by-variable-tp2524754p2524754.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ordering data by variable
Hi Marcio, Is this what you want? x <- c(2,6,8,8,1) y <- c(1,6,3,5,4) o <- order(x) # If you want each vector order by x x[o] y[o] You can also use sort(), but then each vector would be sorted by itself, not both by x. HTH, Josh On Thu, Sep 2, 2010 at 1:48 PM, Mestat wrote: > > Hi listers, > I could order a data that like this: > x<-c(2,6,8,8,1) > y<-c(1,6,3,5,4) > o<-order(x) > frame<-rbind(x,y)[,o] > But, I would like to know if there is a way to order my data without setting > up a data frame. I would like to keep independent vectors x and y. > Any suggestions? > Thanks in advance, > Marcio > -- > View this message in context: > http://r.789695.n4.nabble.com/Ordering-data-by-variable-tp2524754p2524754.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Ordering data by variable
Hi listers, I could order a data that like this: x<-c(2,6,8,8,1) y<-c(1,6,3,5,4) o<-order(x) frame<-rbind(x,y)[,o] But, I would like to know if there is a way to order my data without setting up a data frame. I would like to keep independent vectors x and y. Any suggestions? Thanks in advance, Marcio -- View this message in context: http://r.789695.n4.nabble.com/Ordering-data-by-variable-tp2524754p2524754.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.