Re: [R] Summing certain values within columns that satisfy a certain condition

2015-02-27 Thread Don McKenzie
Use Jeff’s solution. This doesn’t account for ties. On Feb 26, 2015, at 1:11 PM, Don McKenzie d...@u.washington.edu wrote: Kate — here is a transparent solution (tested but without NA treatment). Doubtless there are cleverer faster ones, which later posters will present. HTH #

Re: [R] Summing certain values within columns that satisfy a certain condition

2015-02-27 Thread David L Carlson
of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Don McKenzie Sent: Thursday, February 26, 2015 3:12 PM To: Kate Ignatius Cc: r-help Subject: Re: [R] Summing certain values within columns

Re: [R] Summing certain values within columns that satisfy a certain condition

2015-02-26 Thread Don McKenzie
Kate — here is a transparent solution (tested but without NA treatment). Doubtless there are cleverer faster ones, which later posters will present. HTH # example with four columns and 20 rows nrows - 20 A - sample(c(1:100), nrows, replace=T) B - sample(c(1:100), nrows, replace=T) C -

[R] Summing certain values within columns that satisfy a certain condition

2015-02-26 Thread Kate Ignatius
Hi, Supposed I had a data frame like so: A B C D 0 1 0 7 0 2 0 7 0 3 0 7 0 4 0 7 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 5 0 5 1 5 0 4 1 5 0 8 4 7 0 0 3 0 0 0 3 4 0 0 3 4 0 0 0 5 0 2 0 6 0 0 4 0 0 0 4 0 0 0 4 0 For each row, I want to count how many max column values appear to adventurely get the

Re: [R] Summing certain values within columns that satisfy a certain condition

2015-02-26 Thread Jeff Newmiller
I guess the answer to your question is yes. dta - read.table( text= A B C D 0 1 0 7 0 2 0 7 0 3 0 7 0 4 0 7 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 5 0 5 1 5 0 4 1 5 0 8 4 7 0 0 3 0 0 0 3 4 0 0 3 4 0 0 0 5 0 2 0 6 0 0 4 0 0 0 4 0 0 0 4 0 , header=TRUE ) dtacmax - sapply( dta, max ) followed by