Message-ID: <1362291096.24883.YahooMailClassic@web161205.mail.bf1.yahoo.com>
Date: 2013-03-03T06:11:36Z
From: Matt Borkowski
Subject: Help searching a matrix for only certain records
Let me start by saying I am rather new to R and generally consider myself to be a novice programmer...so don't assume I know what I'm doing :)
I have a large matrix, approximately 300,000 x 14. It's essentially a 20-year dataset of 15-minute data. However, I only need the rows where the column I've named REC.TYPE contains the string "SAO " or "FL-15".
My horribly inefficient solution was to search the matrix row by row, test the REC.TYPE column and essentially delete the row if it did not match my criteria. Essentially...
> j <- 1
> for (i in 1:nrow(dataset)) {
> if(dataset$REC.TYPE[j] != "SAO " && dataset$RECTYPE[j] != "FL-15") {
> dataset <- dataset[-j,] }
> else {
> j <- j+1 }
> }
After watching my code get through only about 10% of the matrix in an hour and slowing with every row...I figure there must be a more efficient way of pulling out only the records I need...especially when I need to repeat this for another 8 datasets.
Can anyone point me in the right direction?
Thanks!
Matt