Re: [R] R equivalent for SQL query

2012-04-03 Thread Henrique Dallazuanna
Here is another way: aggregate(.~ A + B, FUN = length, x) On Tue, Apr 3, 2012 at 3:26 PM, Steven Raemaekers wrote: > Hi, > > I have a query which I would like to translate into R, but I do not know > how to do it in an easy way. > Assume a data frame has columns A, B and C: > > A B

Re: [R] R equivalent for SQL query

2012-04-03 Thread Drew Tyre
As you can see there are lots of ways to get this done! But in vanilla R: test = data.frame(A=rep(1,6),B=c(1,1,1,2,2,3),C=1:6) with(test,aggregate(C,list(A,B),length)) does what you've asked, I think. On Tue, Apr 3, 2012 at 1:26 PM, Steven Raemaekers wrote: > Hi, > > I have a query which I would l

Re: [R] R equivalent for SQL query

2012-04-03 Thread David Winsemius
On Apr 3, 2012, at 3:26 PM, Steven Raemaekers wrote: I'm sorry, but I think that's just plain rude. This is exactly the reason why people do not like to ask for help on mailing lists and internet forums. The usual expectation on this list is for a questioner to demonstrate what was tried

Re: [R] R equivalent for SQL query

2012-04-03 Thread Steven Raemaekers
I'm sorry, but I think that's just plain rude. This is exactly the reason why people do not like to ask for help on mailing lists and internet forums. The help file is full of valuable information, if you know exactly where to look. For someone who doesn't know this, it is rather more complicat

Re: [R] R equivalent for SQL query

2012-04-03 Thread jim holtman
Here is a solution using the data.table package: > x <- read.table(text = "A B C + 1 1 3 + 1 1 4 + 1 1 5 + 1 2 6 + 1 2 7 + 1 3 8", header = TRUE) > require(data.table) > x <- data.table(x) # convert to a data.tabl

Re: [R] R equivalent for SQL query

2012-04-03 Thread andrija djurovic
Hi, here are some solutions: DF <- read.table(textConnection(" A B C 1 1 3 1 1 4 1 1 5 1 2 6 1 2 7 1 3 8 "), header=TRUE) #using sqldf package library(sqldf) sqldf("select A, B, count(*) from DF group

[R] R equivalent for SQL query

2012-04-03 Thread Steven Raemaekers
Hi, I have a query which I would like to translate into R, but I do not know how to do it in an easy way. Assume a data frame has columns A, B and C: A B C 1 1 3 1 1 4 1 1 5 1 2 6 1 2 7 1 3 8 The query is as fol