R: How to prevent memory overflow when using mgsub in vector mode?
问题 I have a long vector of characters (e.g. "Hello World", etc), 1.7M rows, and I need to substitute words in them using a map between two vectors, and save the result in same vector. Here's a simple example: library(qdap) line = c("one", "two one", "four phones") e = c("one", "two") r = c("ONE", "TWO") line = mgsub(e,r,line) Result: [1] "ONE" "TWO ONE" "four phONEs" As you can see, each instance of e[j] in line gets substituted with r[j] and only r[j] . It works fine on a relatively small "line