How to append rows to an R data frame

Update Not knowing what you are trying to do, I’ll share one more suggestion: Preallocate vectors of the type you want for each column, insert values into those vectors, and then, at the end, create your data.frame. Continuing with Julian’s f3 (a preallocated data.frame) as the fastest option so far, defined as: # pre-allocate space … Read more

Compare two data.frames to find the rows in data.frame 1 that are not present in data.frame 2

sqldf provides a nice solution a1 <- data.frame(a = 1:5, b=letters[1:5]) a2 <- data.frame(a = 1:3, b=letters[1:3]) require(sqldf) a1NotIna2 <- sqldf(‘SELECT * FROM a1 EXCEPT SELECT * FROM a2’) And the rows which are in both data frames: a1Ina2 <- sqldf(‘SELECT * FROM a1 INTERSECT SELECT * FROM a2’) The new version of dplyr has … Read more

For each row in an R dataframe

You can use the by() function: by(dataFrame, seq_len(nrow(dataFrame)), function(row) dostuff) But iterating over the rows directly like this is rarely what you want to; you should try to vectorize instead. Can I ask what the actual work in the loop is doing?

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)