Re: [R] Aggregate data frame across columns

2012-11-07 Thread arun
7 #[6,] 0.17196576 0.25992668 0.14820905 0.44368375 0.09780113 0.094327534 A.K. - Original Message - From: Keith Weintraub To: r-help@r-project.org Cc: Sent: Wednesday, November 7, 2012 6:14 PM Subject: Re: [R] Aggregate data frame across columns Arun, Jeff, Bert,   Thanks for yo

Re: [R] Aggregate data frame across columns

2012-11-07 Thread arun
7196576 0.40813573 0.44368375 0.19212866 A.K. - Original Message - From: Keith Weintraub To: r-help@r-project.org Cc: Sent: Wednesday, November 7, 2012 6:14 PM Subject: Re: [R] Aggregate data frame across columns Arun, Jeff, Bert,   Thanks for your help. I have put a subset of my dat

Re: [R] Aggregate data frame across columns

2012-11-07 Thread jim holtman
Here is one way of doing it: # get subset of the column names ss <- substring(names(mySubset), 1, 5) # create the indices of common column colIndx <- split(seq(ncol(mySubset)), ss) rSums <- lapply(colIndx, function(x) rowSums(mySubset[, x], na.rm = TRUE)) # create dataframe newResult <- as.data.fr

Re: [R] Aggregate data frame across columns

2012-11-07 Thread Keith Weintraub
Arun, Jeff, Bert, Thanks for your help. I have put a subset of my data below in mySubset. I would like to be able to sum the rows by year. In this case the results would be the result data.frame below. How can I automate something like this and how would I do it quarterly if necessary. The

Re: [R] Aggregate data frame across columns

2012-11-07 Thread arun
1534 #2004 Q2 1833 #2004 Q3 1445 #2004 Q4 1720 #2005 Q1 1444 #2005 Q2 1630 #2005 Q3 1780 #2005 Q4 1458 A.K. - Original Message - From: Keith Weintraub To: r-help@r-project.org Cc: Sent: Wednesday, November 7, 2012 12:32 PM Subject: [R] Aggregate data frame across columns Folks,   I have a data f

Re: [R] Aggregate data frame across columns

2012-11-07 Thread Jeff Newmiller
The best way to get an answer is to provide sample data and desired results (computed by hand or by any other available means). See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. In the vague question begets a vague answer department, I would use melt fr

Re: [R] Aggregate data frame across columns

2012-11-07 Thread arun
- Original Message - From: Keith Weintraub To: r-help@r-project.org Cc: Sent: Wednesday, November 7, 2012 12:32 PM Subject: [R] Aggregate data frame across columns Folks,   I have a data frame with columns 200401, 200402, ..., 201207, 201208. These represent years/months. What woul

Re: [R] Aggregate data frame across columns

2012-11-07 Thread Bert Gunter
Have you read the Introduction to R tutorial? This is discussed there, I believe. If you have not, please do so before posting here further. But ... ?tapply ?aggregate ?ave Also the plyr package for "user-friendlier" approaches. -- Bert On Wed, Nov 7, 2012 at 9:32 AM, Keith Weintraub wrote: >

[R] Aggregate data frame across columns

2012-11-07 Thread Keith Weintraub
Folks, I have a data frame with columns 200401, 200402, ..., 201207, 201208. These represent years/months. What would be the best way to sum these columns by year? What about by quarter? Thanks for your time, KW -- [[alternative HTML version deleted]] __