Re: [R] Sort problem with merge (again)

2006-09-25 Thread Prof Brian Ripley
On Mon, 25 Sep 2006, Bruce LaZerte wrote: > # R version 2.3.1 (2006-06-01) Debian Linux "testing" > > # Is the following behaviour a bug, feature or just a lack of > # understanding on my part? I see that this was discussed here > # last March with no apparent resolution. Reference? It is the th

Re: [R] Sort problem with merge (again)

2006-09-25 Thread Gabor Grothendieck
If you want it to act like a date store it as a Date: dx <- as.Date(c("1970-04-04","1970-08-11","1970-10-18")) ### x <- c(9,10,11) ch <- data.frame(Date=dx,X=x) dy <- as.Date(c("1970-06-04","1970-08-11","1970-08-18")) ### y <- c(109,110,111) sp <- data.frame(Date=dy,Y=y) merge(ch, sp, all = TRUE

[R] Sort problem with merge (again)

2006-09-25 Thread Bruce LaZerte
# R version 2.3.1 (2006-06-01) Debian Linux "testing" # Is the following behaviour a bug, feature or just a lack of # understanding on my part? I see that this was discussed here # last March with no apparent resolution. d <- as.factor(c("1970-04-04","1970-08-11","1970-10-18")) x <- c(9,10,11) ch

Re: [R] Sort Problem

2006-04-06 Thread Liaw, Andy
From: Sean Davis > > On 4/6/06 8:04 AM, "Sumanta Basak" <[EMAIL PROTECTED]> wrote: > > > Hi All, > > > > > > > > I have certain combinations for which I have some value, e.g. > > > > > > > > 0 1 20 > > > > 0 2 15 > > > > 1 1 40 > > > > 1 2 52 > > > > > >

Re: [R] Sort Problem

2006-04-06 Thread Sean Davis
On 4/6/06 8:04 AM, "Sumanta Basak" <[EMAIL PROTECTED]> wrote: > Hi All, > > > > I have certain combinations for which I have some value, e.g. > > > > 0 1 20 > > 0 2 15 > > 1 1 40 > > 1 2 52 > > > > Now I need to sort this list for which I'll get the c

[R] Sort Problem

2006-04-06 Thread Sumanta Basak
Hi All, I have certain combinations for which I have some value, e.g. 0 1 20 0 2 15 1 1 40 1 2 52 Now I need to sort this list for which I'll get the combination against the lowest value. In this case, 15, and the combination will be 0 2. -- SUMANTA B

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
One other idea; one could use match instead of merge: > # tmp1a and tmp2a from below > cbind(tmp1a, tmp2a[match(tmp1a$col1, tmp2a$col1), -1, drop = FALSE]) col1 col2 1A NA 2A NA 3C1 4C1 50 NA 60 NA This avoids having to muck with reordering of rows and res

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
Sorry, I mixed up out and outa in the last post. Here it is correctly. > levs <- c(LETTERS[1:6], "0") > tmp1a <- data.frame(col1 = factor(c("A", "A", "C", "C", "0", "0"), levs)) > tmp2a <- data.frame(col1 = factor(c("C", "D", "E", "F"), levs), col2 = 1:4) > > out <- merge( cbind(tmp1a, seq = 1:nr

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
On 3/6/06, Gregor Gorjanc <[EMAIL PROTECTED]> wrote: > > But I want to get out > > A NA > A NA > C 1 > C 1 > 0 NA > 0 NA > That's what I get except for the rownames. Be sure to make the factor levels consistent. I have renamed the data frames tmp1a and tmp2a to distinguish them from the ones in

Re: [R] Sort problem in merge()

2006-03-06 Thread Gregor Gorjanc
Gabor and Jean thank you for your time and answers. Gabors approach does not do what I want (with or without sort). Gabor note that when we merge data.frame, this new data.frame gets new row.names and we can not be consistent with sort. > out <- merge(cbind(tmp1, seq = 1:nrow(tmp1)), tmp2, all.x =

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
Actually we don't need sort = FALSE if we are reordering it anyways: out <- merge( cbind(tmp1, seq = 1:nrow(tmp1)), tmp2, all.x = TRUE) out[out$seq, -2] On 3/6/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > I think you will need to reorder it: > > out <- merge( cbind(tmp1, seq = 1:nrow(tmp1)

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
I think you will need to reorder it: out <- merge( cbind(tmp1, seq = 1:nrow(tmp1)), tmp2, all.x = TRUE, sort = FALSE) out[out$seq, -2] On 3/6/06, Gregor Gorjanc <[EMAIL PROTECTED]> wrote: > Gabor Grothendieck wrote: > > If you make the levels the same does that give what you want: > > > > levs

Re: [R] Sort problem in merge()

2006-03-06 Thread Jean Eid
If believe that merge is trying to put first whatever cells that are nonempty. For example if you instead did > tmp2 <- data.frame(col1 = factor(c("C", "D", "E", "F","A"), levs), col2 = 1:5) > tmp2 col1 col2 1C1 2D2 3E3 4F4 5A5 > merge(tmp2, tmp1, al

Re: [R] Sort problem in merge()

2006-03-06 Thread Gregor Gorjanc
Gabor Grothendieck wrote: > If you make the levels the same does that give what you want: > > levs <- c(LETTERS[1:6], "0") > tmp1 <- data.frame(col1 = factor(c("A", "A", "C", "C", "0", "0"), levs)) > tmp2 <- data.frame(col1 = factor(c("C", "D", "E", "F"), levs), col2 = 1:4) > merge(tmp2, tmp1, all

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
If you make the levels the same does that give what you want: levs <- c(LETTERS[1:6], "0") tmp1 <- data.frame(col1 = factor(c("A", "A", "C", "C", "0", "0"), levs)) tmp2 <- data.frame(col1 = factor(c("C", "D", "E", "F"), levs), col2 = 1:4) merge(tmp2, tmp1, all = TRUE, sort = FALSE) merge(tmp1, tmp

[R] Sort problem in merge()

2006-03-06 Thread Gregor Gorjanc
Hello! I am merging two datasets and I have encountered a problem with sort. Can someone please point me to my error. Here is the example. ## I have dataframes, first one with factor and second one with factor ## and integer > tmp1 <- data.frame(col1 = factor(c("A", "A", "C", "C", "0", "0"))) > t