Greetings, I am new to R and have some background knowledge about SQL. I'd like to know whether there is a way to manipulate the R datasets (or data frames) using SQL statements. For example, I have two data frames and both of them have a column called "id", then I want to join this two data frames into one. In SQL, we can just simply use the join comment. What should we do in R? Is there any package that allows us to run SQL statements with R data? Thank you in advance for your help, Willa This message contains confidential information and is in...{{dropped:8}}
The sqldf R package can do that using SQL syntax. See: http://sqldf.googlecode.com The R merge command can do a join but not using SQL syntax. See ?merge On Mon, Jul 14, 2008 at 5:29 PM, Willa Wei <wwei at dataquick.com> wrote:> > Greetings, > > I am new to R and have some background knowledge about SQL. I'd like to > know whether there is a way to manipulate the R datasets (or data > frames) using SQL statements. For example, I have two data frames and > both of them have a column called "id", then I want to join this two > data frames into one. In SQL, we can just simply use the join comment. > What should we do in R? Is there any package that allows us to run SQL > statements with R data? > > Thank you in advance for your help, > Willa > > This message contains confidential information and is in...{{dropped:8}} > > ______________________________________________ > 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. >
Greetings Gabor, is it possible to open a channel to a data frame in the default environment? there are cases when using a sql update statement is the simplest alternative, so instead of dumping the df and then updating and then reimporting it I would like to update the df directly in R. Thank you. Stephen -- View this message in context: http://r.789695.n4.nabble.com/Data-Manipulations-and-SQL-tp860420p2340098.html Sent from the R help mailing list archive at Nabble.com.
On Thu, Aug 26, 2010 at 1:18 PM, stephenb <Stephen.Bond at cibc.com> wrote:> is it possible to open a channel to a data frame in the default environment? > there are cases when using a sql update statement is the simplest > alternative, so instead of dumping the df and then updating and then > reimporting it I would like to update the df directly in R.Assuming that this is a question about sqldf see these links. The first has an example of update and the second discusses connections that persist across sqldf commands: http://code.google.com/p/sqldf/#8._Why_am_I_having_problems_with_update? http://code.google.com/p/sqldf/#Example_10._Persistent_Connections You may also wish to use the RSQLite package directly. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com