0

I have the following MySQL Query using RMySQL. All the Database parameters are set before and Query is working well. Is there a possibility to put it in a loop to get multiple zoo objects from more than one dpname? Thanks!

dpname.df<-"%Name%"

paste.query.df<-paste("select handle from db.connect  where dpname like '",dpname.df,"'",sep='')
handle.df<-dbGetQuery(dbLT,paste.query.df)

paste.query2.df<-paste("select time,value from db.data where handle='",handle.df,"' and time between '",x,"' and '",y,"'",sep='')
df <- dbGetQuery(dbLT,paste.query2.df)


df$time<-as.POSIXct(df$time,format="%Y-%m-%d %H:%M:%S")
df.zoo<-zoo(df[,-1],df[,1])

I tried to set a function with mapply:

query<-function(x,y,dpname.df)
{

    paste.query.df<-paste("select handle from db.connect  where dpname like '",dpname.df,"'",sep='')
    handle.df<-dbGetQuery(dbLT,paste.query.df)

    paste.query2.df<-paste("select time,value from db.data where handle='",handle.df,"' and time between '",x,"' and '",y,"'",sep='')
        dbGetQuery(dbLT,paste.query2.df)

}

which I can run: with mapply(query,x,y,dpname.df)

But I can't get multiple outputs for each! query. Is it possible to set another List with the output names? So I could also put the zoo and POSIXct stuff in my function.Thanks!

Herr Student
  • 853
  • 14
  • 26
  • I confess that I don't understand what you are asking. You say you can't get multiple outputs for each query, but I have no idea what that means. A random guess: maybe setting `SIMPLIFY = FALSE` in `mapply` would help? – joran Feb 19 '14 at 15:18
  • My first thought was to generate a loop with an output for every query: output1, output2, output3. The names oft these matrix defined by another list(). – Herr Student Feb 19 '14 at 15:46
  • You haven't actually explained what your specific problem is. I can't tell if your problem is actually running the queries, or if you can run them, but you're trying to organize the results in a specific way. – joran Feb 19 '14 at 15:50
  • Thanks joran for you reply - I wrote query is working well;-) I am realy trying to organize the output: I want one variable for each run of the function, having a defined name (e.g. defined by list). – Herr Student Feb 19 '14 at 15:52
  • Sounds like my original suggestion was correct: use `SIMPLIFY = FALSE` in `mapply` and set the names of the result using `names()`. – joran Feb 19 '14 at 15:55

0 Answers0