This isn't the most beautiful code, but I think it should work for you: # Some sample data M = cbind(matrix(rnorm(10),ncol=2),matrix(sample(c(10,1),15,replace=T),ncol=3)) colnames(M) = c("Thing1","Thing2",paste("array",1:3,sep=""))
colsToCheck = grepl("array",colnames(M)) # Isolate the "array" columns rowsToKeep = apply(M[,colsToCheck],1,function(x){any (x != 10)}) # apply the test function row-wise to get a logical vector of which rows to keep Answer = M[rowsToKeep,] # keep only those rows Hope this helps, Michael On Mon, Aug 22, 2011 at 12:56 PM, Changbin Du <changb...@gmail.com> wrote: > HI, Michael, > > What I want to do is remove all the rows, for which array1, array2, > ..array15 are all equal to 10. > > I want to keep all the rows at least one of the array variables are not > equal to 10. > > sorry for the confusion. > > > > > > On Mon, Aug 22, 2011 at 9:52 AM, R. Michael Weylandt < > michael.weyla...@gmail.com> wrote: > >> "I want to select the array columns that are not equal to 10." is >> ambiguous to me. >> >> Just to clarify, do you want to simply drop the column named array10 or do >> you want to check each column for having one/all 10's as values and drop >> based on that test? >> >> Michael >> >> On Mon, Aug 22, 2011 at 12:35 PM, Changbin Du <changb...@gmail.com>wrote: >> >>> Dear R community, >>> >>> I have a data set like the following: >>> >>> probe_name chr_id position array1 array2 array3 array4 array5 array6 >>> array7 >>> 1 C-3AAAA 10 16566949 10 10 10 10 10 10 >>> 10 >>> 2 C-3AAAB 17 33478940 10 10 10 10 10 10 >>> 10 >>> 3 C-3AAAC 3 187369224 10 10 2 10 10 1 >>> 10 >>> 4 C-3AAAD 8 28375041 10 10 10 10 10 10 >>> 10 >>> 5 C-3AAAG 13 99134921 10 10 10 10 10 10 >>> 10 >>> 6 C-3AAAH 16 31565412 10 10 10 10 10 10 >>> 10 >>> array8 array9 array10 array11 array12 array13 array14 array15 >>> 1 10 10 10 10 10 10 10 10 >>> 2 10 10 10 10 10 10 10 10 >>> 3 10 10 10 10 10 10 10 10 >>> 4 10 10 10 10 10 10 10 10 >>> 5 10 10 10 10 10 1 10 10 >>> 6 10 10 10 0 10 10 10 10 >>> >>> I want to select the array columns that are not equal to 10. >>> >>> I tried the following codes: >>> >>> head(reduce.final<-final[which(final$array*!=10), ]) # it does not >>> wok, >>> do any one have a smart to do this? >>> >>> Thanks so much! >>> >>> >>> -- >>> Sincerely, >>> Changbin >>> -- >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> > > > -- > Sincerely, > Changbin > -- > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.