0

I try to create a loop that will create data frames by using different sql queries that have the same name exept the day number.For example here is the name for query that is for day 1 :SF_2013_Day1_BaseLine and this is for day 6: SF_2013_Day6_BaseLine. I wrote this code (below) but I got an error : Error: unexpected ',' in "for(i in 3," .So any Idea how can i get this code to work ? Thank you

for (i in 1,3,6,10,14,21,30) {
    SF_FinalviewQ3_2013_Day[i]_BaseLine<-sqlQuery(DB,"select * from [SF_2013_Day[i]_BaseLine]");
    dim(SF_Day[i]_BaseLine)}

After a change based on @Pgibas edvice to this code :

 for (i in c(1,3,6,10,14,21,30)) {
        SF_FinalviewQ3_2013_Day[i]_BaseLine<-sqlQuery(DB,"select * from [SF_2013_Day[i]_BaseLine]");
        dim(SF_Day[i]_BaseLine)}

I got this error: Error: unexpected input in "for(i in c(3,6)){glm_d[i]_" . What can I do to resolve the problem?

3
  • 1
    Just to solve you problem: for (i in c(1,3,6,10,14,21,30)) { ... } Commented Apr 21, 2015 at 12:23
  • thanks @Pgibas, but now i get another error: Error: unexpected input in "for(i in c(3,6)){glm_d[i]_" . I didn't wrote functions like this until now so I don't know how check what is wrong. Commented Apr 21, 2015 at 12:30
  • Edit your question, can't understand what you wrote in comment. Commented Apr 21, 2015 at 12:40

1 Answer 1

1

You need to resolve i within the names first:

for (i in c(1,3,6,10,14,21,30)) {
  set <- sqlQuery(DB, paste0("select * from [SF_2013_Day[", i, "]_BaseLine]"))
  eval(parse(text = paste0("SF_FinalviewQ3_2013_Day", i, "_BaseLine <- set"))
  dim(set)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.