Skip to content

cumulative sum by group and under some criteria

4 messages · arun, Zjoanna, Jeff Newmiller +1 more

#
dat1<- read.table(text="
m1 n1 m n??? A????? B??? C?? D
2??? 2??? 4? 5? 0.1??? 0.2? 0.2 0.3
2?? 2???? 4? 4? 0.2?? 0.1?? 0.3? 0.4
2?? 3???? 4? 5? 0.5?? 0.6?? 0.2? 0.2
2? 4????? 3? 4? 0.2?? 0.8?? 0.5? 0.3
",sep="",header=TRUE) 


dat1[which.max(dat1$D),]
#? m1 n1 m n?? A?? B?? C?? D
#2? 2? 2 4 4 0.2 0.1 0.3 0.4
A.K.
#
Read The Fine Manual... the document "An Introduction to R" is supplied with R, and section 10 discusses functions. (Macros are not supported.) Depending on what you want to parameterize, a review of indexing and lists (section 2.7, 5.3, and 6) is likely to be needed as well. This is a valuable document to be familiar with, though I recommend avoiding the use of attach/detach discussed in 6.3.2.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.
Zjoanna <Zjoanna2013 at gmail.com> wrote:

            
#
This is no longer a question for which the Subject is accurate. Please do not continue using inaccurate subject lines.
On Feb 27, 2013, at 9:38 AM, Zjoanna wrote:

            
Try:
[[1]]
  m1 n1 m n   A   B   C   D
3  2  3 4 5 0.5 0.6 0.2 0.2

[[2]]
  m1 n1 m n   A   B   C   D
4  2  4 3 4 0.2 0.8 0.5 0.3

[[3]]
  m1 n1 m n   A   B   C   D
4  2  4 3 4 0.2 0.8 0.5 0.3

[[4]]
  m1 n1 m n   A   B   C   D
2  2  2 4 4 0.2 0.1 0.3 0.4