Looks like your event id is unique. If that is so, why not just do
##Not checked
events <- events[sort(events$event),]
dataF <- dataF[sort(data$event),]
if(doUpdate == 1){
if(!is.null(dataF) && nrow(dataF) > 0){
events[events$eventid %in% dataF$event, c("timestamp",
"isSynchronized","timediff)] <- cbind(dataF[,"tobiitime"],
rep(1,nrow(dataF), (dataF[i,"ruiTime"]-dataF[,"tobiitime"]))
}
Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina
nikhil.l...@gmail.com
On Jul 22, 2010, at 2:04 PM, harsh yadav wrote:
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.
______________________________________________
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.