Today I was wondering how I could extract certain entries (≥0.95) from a huge matrix in R containing about 1.5 billion float values.
I had this simple condition on the values, and I wanted to iterate over all entries that satisfied that condition and write them to a file.
After some fiddling I found I quick way of doing so:
We make use of the which-function, which is capable of extracting indices from matrices that fulfill certain conditions and then use the apply function:
trueIndices <- which(matrix ≥ 0.95, arr.ind=TRUE)
apply(trueIndices, MARGIN=1, writeFunction)