Question

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!

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top