Re: [R] Counting by rows based on multiple criteria

2010-02-08 Thread Steve Murray
Spot on, thanks very much indeed. Steve _ Got a cool Hotmail story? Tell us now __ R-help@r-project.org mailing list https://stat.ethz.ch/mailma

Re: [R] Counting by rows based on multiple criteria

2010-02-08 Thread jim holtman
Will this do it for you: > x <- matrix(sample(c(-1,0,1), 6000, TRUE), ncol=6) > # compute the occurances > gt0 <- rowSums(x > 0) > lt0 <- rowSums(x < 0) > eq0 <- rowSums(x == 0) > x <- cbind(x, result=ifelse(eq0 == 6, -, + ifelse(gt0 > lt0, gt0, + ifelse(gt0 == lt0, 0, -lt0 > head(

[R] Counting by rows based on multiple criteria

2010-02-08 Thread Steve Murray
Dear all, I have a data frame of 6 columns and ~6 rows which I hope to perform the following calculation on. For each row, I wish to determine whether there are a greater number of positive or negative numbers. Then, if there are more positive numbers in the row, count how many occur - bu