Re: [R] Logical subset of the columns in a dataframe

2009-01-28 Thread David Winsemius
One approach to such a problem would be to use a logical vector inside the function colSums. ?colSums > DF <- data.frame(XX= runif(20), YY=runif(20)) > colSums(DF > 0.5) XX YY 11 9 > colSums(DF > -Inf) XX YY 20 20 > > colSums(DF> 0.5)/colSums(DF > -Inf) #could have used DF >= min(DF) in t

Re: [R] Logical subset of the columns in a dataframe

2009-01-28 Thread Prof Brian Ripley
On Wed, 28 Jan 2009, Mark Na wrote: Hi R-helpers, I've been struggling with a problem for most of the day (!) so am finally resorting to R-help. I would like to subset the columns of my dataframe based on the frequency with which the columns contain non-zero values. For example, let's say that