Hi R-experts, I have a data frame (A) , and a subset (B) of this data frame. I am trying to create a new data frame which gives me all the rows of B, plus the 5th next row(occuring in A). I have used the below code, but it gives me all 5 rows after the matching row. I only want the 5th. FiveDaysLater <- A[c(sapply(match(rownames(B),rownames(A)), seq, length=6))),] Any guidance much appreciated, Thankyou. Alfonso Sammassimo Melbourne, Australia.
Dear list, I have a very short question, Suggest a dataframe of four columns. df <- data.frame(w,x,y,z) I want this ordered the following way: first by :x, decreasing = FALSE and secondly by: z, decreasing =TRUE How can this be done ? Thanks Gunther
probably the function sort.data.frame() posted in R-help some time ago can be useful; check: RSiteSearch("sort.data.frame") I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Gunther H?ning" <gunther.hoening at ukmainz.de> To: <r-help at stat.math.ethz.ch> Sent: Friday, June 08, 2007 8:58 AM Subject: [R] Sorting dataframe by different columns> Dear list, > > I have a very short question, > Suggest a dataframe of four columns. > > df <- data.frame(w,x,y,z) > > I want this ordered the following way: > first by :x, decreasing = FALSE > and > secondly by: z, decreasing =TRUE > > How can this be done ? > > Thanks > > Gunther > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
try: FiveDaysLater <- A[match(rownames(B),rownames(A))+5,] On 6/7/07, Alfonso Sammassimo <cincinattikid@bigpond.com> wrote:> > Hi R-experts, > > I have a data frame (A) , and a subset (B) of this data frame. I am trying > to create a new data frame which gives me all the rows of B, plus the 5th > next row(occuring in A). I have used the below code, but it gives me all > 5 > rows after the matching row. I only want the 5th. > > FiveDaysLater <- A[c(sapply(match(rownames(B),rownames(A)), seq, > length=6))),] > > Any guidance much appreciated, > Thankyou. > > Alfonso Sammassimo > Melbourne, Australia. > > ______________________________________________ > R-help@stat.math.ethz.ch 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]]
On the R wiki site there is a general-purpose function (sort.data.frame) that allows you to do this: sort(df, by=~ x-z) See: http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:sort Regards, Kevin On 6/8/07, Gunther H?ning <gunther.hoening at ukmainz.de> wrote:> Dear list, > > I have a very short question, > Suggest a dataframe of four columns. > > df <- data.frame(w,x,y,z) > > I want this ordered the following way: > first by :x, decreasing = FALSE > and > secondly by: z, decreasing =TRUE > > How can this be done ? > > Thanks > > Gunther > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >