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

2015-02-27 Thread David L Carlson
David L Carlson Department of Anthropology Texas A&M 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] Su

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 wrote: > > 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 co

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 <- sampl

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 b

[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