Hi, I have a global data-frame in my R script.
At some point in my script, I want to update certain columns of this data-frame by calling in an update function. The function looks like this: # get events data. This populates a global event data frame in the R-script events <- getEvents(con, eventsFilePath) # events has columns eventid, timeStamp, isSynchronized, timeDiff; with millions of rows updateDB <- function(eventid, newTimeStamp, oldTimeStamp){ timeDiff <- newTimeStamp - oldTimeStamp #Update the events Data Frame events[events$eventid == eventid, "timestamp"] <<- newTimeStamp events[events$eventid == eventid, "isSynchronized"] <<- 1 events[events$eventid == eventid, "timeDiff"] <<- timeDiff } I call this function like: # dataF is a subset of events if(doUpdate == 1){ if(!is.null(dataF) && nrow(dataF) > 0){ len <- nrow(dataF) for(i in 1:len){ updateDB(dataF[i,"eventid"], dataF[i,"tobiiTime"], dataF[i,"ruiTime"]) } } } However, this particular update functionality is performing very slow updates. Is there a better and more efficient way to update multiple fields in a data-frame efficiently. Thanks in advance. Harsh Yadav [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.