Re: [R] data frames; matching/merging

2010-02-08 Thread Gabor Grothendieck
Here are 3 solutions assuming DF contains the data frame: > # 1. aggregate > aggregate(DF[2], DF[1], min) V1 V2 1 a 2 2 b 9 3 c 4 > # 2. aggregate.formula - requires R 2.11.x > aggregate(V2 ~ V1, DF, min) V1 V2 1 a 2 2 b 9 3 c 4 > # 3. SQL using sqldf > library(sqldf) > sqldf("se

Re: [R] data frames; matching/merging

2010-02-08 Thread hadley wickham
On Mon, Feb 8, 2010 at 10:39 AM, Jonathan wrote: > Hi all, >    I'm feeling a little guilty to ask this question, since I've > written a solution using a rather clunky for loop that gets the job > done.  But I'm convinced there must be a faster (and probably more > elegant) way to accomplish what

Re: [R] data frames; matching/merging

2010-02-08 Thread S Ellison
You could try aggregate: If we call your data frame df: aggregate(df[2], by=df[1], FUN=min) will get you what you asked for (if not necessarily what you need ;-) ) Switching the columns around is easy enough if you need to; proceeding stepwise: df.new<-aggregate(df[2], by=df[1], FUN=min) df.new

Re: [R] data frames; matching/merging

2010-02-08 Thread David Winsemius
On Feb 8, 2010, at 11:39 AM, Jonathan wrote: Hi all, I'm feeling a little guilty to ask this question, since I've written a solution using a rather clunky for loop that gets the job done. But I'm convinced there must be a faster (and probably more elegant) way to accomplish what I'm looking

Re: [R] data frames; matching/merging

2010-02-08 Thread jim holtman
> x <- read.table(textConnection("V1 V2 + 1a3 + 2a2 + 3b9 + 4c4 + 5a7 + 6b11"), header=TRUE) > closeAllConnections() > # close; matrix with rownames - easy enough to change into a dataframe if you > want > cbind(tapply

Re: [R] data frames; matching/merging

2010-02-08 Thread Ivan Calandra
Hi! I'm definitely not an expert in R (and it's my first reply!), but if I understand right, I think the aggregate function might do what you're looking for. Try ?aggregate to get more info. You might find what you need! HTH Ivan Le 2/8/2010 17:39, Jonathan a écrit : Hi all, I'm feel

Re: [R] data frames; matching/merging

2010-02-08 Thread jim holtman
On Mon, Feb 8, 2010 at 11:39 AM, Jonathan wrote: > Hi all, >    I'm feeling a little guilty to ask this question, since I've > written a solution using a rather clunky for loop that gets the job > done.  But I'm convinced there must be a faster (and probably more > elegant) way to accomplish what