Subcategory: None · Core

Don't Grow data.frame(s)

When you grow a data.frame by one, for example using rbind() or cbind() to add a row or column, R will allocate a new data.frame one larger and copy across all the old data. If you’re doing this regularly, that’s alot of redundant expensive memory movement. Either pre-allocate your data.frame to the correct size at the start, or use a data.table instead which provides faster growth (and many other performance improvements).

Read More

Vectorisation

R has many functions which operate on entire vectors and matrices, which have been implemented in faster C. Vectorisation can perform mathematical operations many times faster than a for loop and even take advantage of conditional logic.

Read More