[R] For loop and sqldf

From: mathijsdevaan <mathijsdevaan_at_gmail.com>
Date: Fri, 29 Apr 2011 13:27:43 -0700 (PDT)


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))
for (t in 1:length(list))
	{
	year = as.character(list[t])
	data[year]<-sqldf('select * from DF where C = [year]')
 	}

I am trying to split up the data.frame into 5 new ones, one for every year.

--
View this message in context: http://r.789695.n4.nabble.com/For-loop-and-sqldf-tp3484559p3484559.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.
Received on Fri 29 Apr 2011 - 20:59:29 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 Fri 29 Apr 2011 - 23:50:33 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