I am using ddply to split up a data frame and send the chunks to a function. Before the ddply line, I set i=1. Then inside the function I am incrementing i so that each chunk of data gets a new number. When I run this, however, i is being reset to 1 each time the function is called. I assume this is because the i outside the function is being reassigned each time ddply sends a new chunk of data. Is there a way to increment outside the function and send that number along with the data?
EDIT::
Here is the calling line:
rseDF <- ddply(rseDF, .(TestCompound), .fun = setTheSet)
Here is the function:
##Set The Set Column
setTheSet <- function(df) {
if (df[,"TestCompound"] == "DNS000000001") df[,"Set"] <- "Control"
else {df[,"Set"] <- i
i <<- i+1}
return(df)
}
That is just a normal scoping issue where you, if you insist on doing this, need to use
<<-for the global assignment: