Dimitri Shvorob
2010-Jan-23 22:46 UTC
[R] How to implement a "select distinct x, count(distinct y) ... group by x" for a data frame
... Being an R newbie, I can only think of extracting distinct x values with unique, looping over them, extracting matching rows from the original data frame, applying table, and recording the size of table's output alongside the x value being checked. Is there a more elegant way? Thank you. -- View this message in context: http://n4.nabble.com/How-to-implement-a-select-distinct-x-count-distinct-y-group-by-x-for-a-data-frame-tp1288418p1288418.html Sent from the R help mailing list archive at Nabble.com.
jim holtman
2010-Jan-24 00:24 UTC
[R] How to implement a "select distinct x, count(distinct y) ... group by x" for a data frame
Yes. ?sqldf ?split ?lapply But unless you provide commented, minimal, self-contained, reproducible code, it is hard to say how to proceed to a solution. On Sat, Jan 23, 2010 at 5:46 PM, Dimitri Shvorob <dimitri.shvorob at gmail.com> wrote:> > ... Being an R newbie, I can only think of extracting distinct x values with > unique, looping over them, extracting matching rows from the original data > frame, applying table, and recording the size of table's output alongside > the x value being checked. Is there a more elegant way? > > Thank you. > -- > View this message in context: http://n4.nabble.com/How-to-implement-a-select-distinct-x-count-distinct-y-group-by-x-for-a-data-frame-tp1288418p1288418.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Gabor Grothendieck
2010-Jan-24 00:31 UTC
[R] How to implement a "select distinct x, count(distinct y) ... group by x" for a data frame
Regarding your subject, the sqldf package on CRAN allows you to apply SQL statements directly to R data frames. http://sqldf.googlecode.com On Sat, Jan 23, 2010 at 5:46 PM, Dimitri Shvorob <dimitri.shvorob at gmail.com> wrote:> > ... Being an R newbie, I can only think of extracting distinct x values with > unique, looping over them, extracting matching rows from the original data > frame, applying table, and recording the size of table's output alongside > the x value being checked. Is there a more elegant way? > > Thank you. > -- > View this message in context: http://n4.nabble.com/How-to-implement-a-select-distinct-x-count-distinct-y-group-by-x-for-a-data-frame-tp1288418p1288418.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >
Dimitri Shvorob
2010-Jan-24 00:59 UTC
[R] How to implement a "select distinct x, count(distinct y) ... group by x" for a data frame
sqldf answered my prayers and more. Thanks a lot! -- View this message in context: http://n4.nabble.com/How-to-implement-a-select-distinct-x-count-distinct-y-group-by-x-for-a-data-frame-tp1288418p1288489.html Sent from the R help mailing list archive at Nabble.com.