Skip to content
Prev 170104 / 398506 Next

Filter a big matrix

On Wed, Feb 11, 2009 at 1:32 PM, cruz <cruadam at gmail.com> wrote:
Assuming that I understood your data structure correctly, that all
columns should be tested in your filter, and that exactly one column
should not match the condition, the following should work:


##sample data
X<-matrix(sample(1:200,10000,replace=T),nrow=100)
colnames(X)<-1:100

### Filter function - modify to suit your purpose
filterFunction<-function(n,data){
filteredData<-data[rowSums(data>=199)==1&(data[,n]>=199),,drop=FALSE]
if(nrow(filteredData)==0){
    filteredData<-"NoMatchingRows"
    }
return(filteredData)
}

names<-colnames(X)
lapply(as.list(names),filterFunction,X)


Hope it helps.
Best regards,
Gustaf