Putting SQL columns/variables into square brackets is valid syntax for sqlite. 
Expecting sqlite to share variables with R is not, so there was only one 
necessary change.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

David Winsemius <dwinsem...@comcast.net> wrote:

On Apr 29, 2011, at 4:27 PM, mathijsdevaan wrote: > Hi list, > > Can anyone 
tell my why the following does not work? Thanks a lot! > Your help > is very 
much appreciated. > > DF = data.frame(read.table(textConnection(" B C D E F G > 
8025 1995 0 4 1 2 > 8025 1997 1 1 3 4 > 8026 1995 0 7 0 0 > 8026 1996 1 2 3 0 > 
8026 1997 1 2 3 1 > 8026 1998 6 0 0 4 > 8026 1999 3 7 0 3 > 8027 1997 1 2 3 9 > 
8027 1998 1 2 3 1 > 8027 1999 6 0 0 2 > 8028 1999 3 7 0 0 > 8029 1995 0 2 3 3 > 
8029 1998 1 2 3 2 > 8029 1999 6 0 0 1"),head=TRUE,stringsAsFactors=FALSE)) 
list<-sort(unique(DF$C)) ; require(sqldf); data <-list() # added inits > for (t 
in 1:length(list)) >        { >     year = as.character(list[t]) >  
data[year]<-sqldf('select * from DF where C = [year]') #I see you have already 
gotten a workable answer, but thought you might want to see if this would work: 
 data[year]<-sqldf(paste('select * from DF where C = ', year, sep="") ) # Two 
changes ... let `year` get evaluated and don't put `year` in brack
 ets. >
        } > > data $`1995` [1] 8025 8026 8029 $`1996` [1] 8026 $`1997` [1] 8025 
8026 8027 $`1998` [1] 8026 8027 8029 $`1999` [1] 8026 8027 8028 8029 > I am 
trying to split up the data.frame into 5 new ones, one for > every year. > > > 
-- David Winsemius, MD West Hartford, 
CT_____________________________________________
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.

Reply via email to