I have a data frame called MetricsInput which looks like this:
ID ExtractName Dimensions Metrics First_Ind
124 extract1.txt ga:date gs:sessions 1
128 extract1.txt ga:date gs:sessions 0
134 extract1.txt ga:date gs:sessions 0
124 extract2.txt ga:browser ga:users 1
128 extract2.txt ga:browser ga:users 0
134 extract2.txt ga:browser ga:users 0
I'm trying to use the above data frame in a loop to run a series of queries, which ultimately will create 2 text files, extract1.txt and extract2.txt. The reason I have the first_ind field is I only want to append the column headings on the first run through each unique file.
Here's my loop -- the issue I'm having is that the data for each ID is not appending -- I seem to be overwriting my results, not appending. Where did I go wrong?
for(i in seq(from=1, to=nrow(MetricsInput), by=1)){
id <- MetricsInput[i,1]
myresults <- ga$getData(id,batch = TRUE, start.date="2013-12-01", end.date="2014-01-01", metrics = MetricsInput[i,4], dimensions = MetricsInput[i,3])
appendcolheads <- ifelse(MetricsInput[i,5]==1, TRUE, FALSE)
write.table(myresults, file=MetricsInput$ExtractName[i], append=TRUE, row.names = FALSE, col.names = appendcolheads, sep="\t")
}