Re: [R] counting columns that match criteria

2011-11-10 Thread Dennis Murphy
Hi: Here's a toy example: # Default var names are V1-V20: u <- as.data.frame(matrix(rpois(100, 3), ncol = 20)) u <- transform(u, ngt1 = apply(u[, c('V1', 'V4', 'V9', 'V15')], 1, function(x) sum(x > 1)) ) u HTH, Dennis On Thu, Nov 10, 2011 at 7:24 AM, JL Villanueva wrote: > Hi, > > I am a l

Re: [R] counting columns that match criteria

2011-11-10 Thread Jorge I Velez
Hi JL, How about the following? rowSums(d >1) # d is your data Best, Jorge.- On Thu, Nov 10, 2011 at 10:24 AM, JL Villanueva <> wrote: > Hi, > > I am a little new in R but I'm finding it extremely useful :) > > Here's my tiny question: > > I've got a table with a lot of columns. What I am in

Re: [R] counting columns that match criteria

2011-11-10 Thread jim holtman
try this: > x Col1 Col2 Col3 Col4 11111 22111 34141 43333 > apply(x, 1, function(a) sum(a > 1)) [1] 0 1 2 4 > x$count <- apply(x, 1, function(a) sum(a > 1)) > x Col1 Col2 Col3 Col4 count 11111 0 221

[R] counting columns that match criteria

2011-11-10 Thread JL Villanueva
Hi, I am a little new in R but I'm finding it extremely useful :) Here's my tiny question: I've got a table with a lot of columns. What I am interested now is to evaluate how many of 4 columns have a value greater than 1. I think it can be done with subset() but it will take a very long conditio