Re: [R] drop unused levels in sqldf
Thanx guys, practical and effective solutions. Gianandrea glaporta wrote: > > Hi, > sqldf is a fantastic package, but when the SELECT procedure runs unused > levels remain in the output. I tried with the drop function, but without > success. Do you have any suggestions? > Thanx, Gianandrea > > data(iris) > require(sqldf) > base<-sqldf("select * from iris where Species <> 'setosa'") > str(base) # Species with 3 levels! > > -- View this message in context: http://www.nabble.com/drop-unused-levels-in-sqldf-tp19196464p19215127.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] drop unused levels in sqldf
Here are two approaches: 1. rename the column to circumvent the column classing heuristic. In the following Species will be a 3-level factor and Species2 will be a 2-level factor sqldf("select *, Species as Species2 from iris where Species <> 'setosa'") 2. use method = "raw". This code below returns Species as a "character" vector and then we make it a factor manually: out <- sqldf("select * from iris where Species <> 'setosa'", method = "raw") out$Species <- as.factor(out$Species) There is more discussion in the Heuristic section of the home page: http://sqldf.googlecode.com On Thu, Aug 28, 2008 at 4:36 AM, glaporta <[EMAIL PROTECTED]> wrote: > > Hi, > sqldf is a fantastic package, but when the SELECT procedure runs unused > levels remain in the output. I tried with the drop function, but without > success. Do you have any suggestions? > Thanx, Gianandrea > > data(iris) > require(sqldf) > base<-sqldf("select * from iris where Species <> 'setosa'") > str(base) # Species with 3 levels! > > -- > View this message in context: > http://www.nabble.com/drop-unused-levels-in-sqldf-tp19196464p19196464.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@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. > __ R-help@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.
Re: [R] drop unused levels in sqldf
If you want to suppress the unused level of Species, you can use factor() : table(base$Species) table(factor(base$Species)) 2008/8/28 glaporta <[EMAIL PROTECTED]> > > Hi, > sqldf is a fantastic package, but when the SELECT procedure runs unused > levels remain in the output. I tried with the drop function, but without > success. Do you have any suggestions? > Thanx, Gianandrea > > data(iris) > require(sqldf) > base<-sqldf("select * from iris where Species <> 'setosa'") > str(base) # Species with 3 levels! > > -- > View this message in context: > http://www.nabble.com/drop-unused-levels-in-sqldf-tp19196464p19196464.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@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. > [[alternative HTML version deleted]] __ R-help@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.
[R] drop unused levels in sqldf
Hi, sqldf is a fantastic package, but when the SELECT procedure runs unused levels remain in the output. I tried with the drop function, but without success. Do you have any suggestions? Thanx, Gianandrea data(iris) require(sqldf) base<-sqldf("select * from iris where Species <> 'setosa'") str(base) # Species with 3 levels! -- View this message in context: http://www.nabble.com/drop-unused-levels-in-sqldf-tp19196464p19196464.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.