[R-sig-DB] Vector Operations

Kasper Daniel Hansen k@@perd@n|e|h@n@en @end|ng |rom gm@||@com
Wed Dec 1 14:27:39 CET 2010


This is a pretty basic R question.  For you own sake, I would
recommend looking into lapply, sapply, mapply

In this case you could do

allocatedSpace <- lapply(sql, dbGetQuery, con = con)

This code assumes that the relevant position of the argument is the
second one in dbGetQuery.  A more future proof version would be
something like

allocatedSpace <- lapply(sql, function(state) dbGetQuery(con = con,
statement = state))

Kasper

On Mon, Nov 29, 2010 at 9:34 PM, Nick Torenvliet
<nick.torenvliet using gmail.com> wrote:
> This isn't strictly an DB question, but I'll venture out anyways...
>
> I've got a vector of sql statements called sql
>
>> sql
> [1] "select date, open, high, low, close, volume from endOfDayData where
> date>'2009-09-01' and market like 'TSX' and symbol like 'AAB' order by date"
> .
> .
> .
> [2464] "select date, open, high, low, close, volume from endOfDayData where
> date>'2009-09-01' and market like 'TSX' and symbol like 'ZUH' order by date"
>
> [2465] "select date, open, high, low, close, volume from endOfDayData where
> date>'2009-09-01' and market like 'TSX' and symbol like 'ZUT' order by
> date"
>
> For each element in sql I'd like to run the queries in sql and have them in
> another vector of some sort as in the following for loop...
>
> for(x in sql){
> allocatedSpace <- dbGetQuery(con, statement=x)
> }
>
> Is there a way to do this in a more R-esque vector like fashion/single line?
>
> Regards,
>
> Nick
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-DB mailing list -- R Special Interest Group
> R-sig-DB using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-db
>




More information about the R-sig-DB mailing list