Re: [R] SQLDF syntax

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 19 Apr 2011 05:48:49 -0400

On Mon, Apr 18, 2011 at 6:34 PM, new2R <bv_agrico_at_yahoo.co.in> wrote:
> Hi,
>
> I am new to R and trying to migrate from SAS. I am trying to use sqldf to
> create a new table from existed table and change some of the columns. I have
> table called DataOld with columns commodity, rate and total and I am trying
> to create new table called DataNew with columns commodity, ratenew and
> totalNew.
>
>> sqldf("create table datanew as select commodity, ratenew as rate * 10,
>> totalnew as total *10 from DataOld")
>
> I got error message " Error in sqliteExecStatement(con, statement,
> bind.data) :
>  RS-DBI driver: (error in statement: near "*": syntax error)
>

Its expression as name, not name as expression. Try this:

> library(sqldf)
> BODnew <- sqldf("select demand, Time, demand + 1 as demandPlusOne from BOD")
> BODnew

  demand Time demandPlusOne

1    8.3    1           9.3
2   10.3    2          11.3
3   19.0    3          20.0
4   16.0    4          17.0
5   15.6    5          16.6
6   19.8    7          20.8

For more, the sqldf home page at http://sqldf.googlecode.com has links to sqlite site where you can find sql syntax diagrams. See the links along the left side of the page there.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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.
Received on Tue 19 Apr 2011 - 09:50:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Apr 2011 - 10:00:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive