[R] ?max (so far...)

2009-07-01 Thread Mark Knecht
Hi, I have a data.frame that is date ordered by row number - earliest date first and most current last. I want to create a couple of new columns that show the max and min values from other columns *so far* - not for the whole data.frame. It seems this sort of question is really coming from m

[R] ?max (so far...)

2009-07-01 Thread Carl Witthoft
> More generally, you can always write a loop. They aren't necesssrily fast > or elegant, but they're pretty general. For example, to calculate the max > of the previous 50 observations (or fewer near the start of a vector), you > could do > > x <- ... some vector ... > > result <- numeric(le

Re: [R] ?max (so far...)

2009-07-01 Thread Duncan Murdoch
On 01/07/2009 11:49 AM, Mark Knecht wrote: Hi, I have a data.frame that is date ordered by row number - earliest date first and most current last. I want to create a couple of new columns that show the max and min values from other columns *so far* - not for the whole data.frame. It seems

Re: [R] ?max (so far...)

2009-07-01 Thread Mark Knecht
On Wed, Jul 1, 2009 at 9:39 AM, Duncan Murdoch wrote: > On 01/07/2009 11:49 AM, Mark Knecht wrote: >> >> Hi, >>   I have a data.frame that is date ordered by row number - earliest >> date first and most current last. I want to create a couple of new >> columns that show the max and min values from

Re: [R] ?max (so far...)

2009-07-01 Thread Duncan Murdoch
On 01/07/2009 1:26 PM, Mark Knecht wrote: On Wed, Jul 1, 2009 at 9:39 AM, Duncan Murdoch wrote: On 01/07/2009 11:49 AM, Mark Knecht wrote: Hi, I have a data.frame that is date ordered by row number - earliest date first and most current last. I want to create a couple of new columns that show

Re: [R] ?max (so far...)

2009-07-01 Thread Mark Knecht
On Wed, Jul 1, 2009 at 12:54 PM, Duncan Murdoch wrote: > On 01/07/2009 1:26 PM, Mark Knecht wrote: >> >> On Wed, Jul 1, 2009 at 9:39 AM, Duncan Murdoch >> wrote: >>> >>> On 01/07/2009 11:49 AM, Mark Knecht wrote: Hi,  I have a data.frame that is date ordered by row number - earliest

Re: [R] ?max (so far...)

2009-07-01 Thread baptiste auguie
For another generic approach, you might be interested in the Reduce function, rolling <- function( x, window=seq_along(x), f=max){ Reduce(f, x[window]) } x= c(1:10, 2:10, 15, 1) rolling(x) #15 rolling(x, 1:10) #10 rolling(x, 1:12) #10 Of course this is only part of the solution to the

Re: [R] ?max (so far...)

2009-07-01 Thread Petr PIKAL
Hi what about do inside some function a subset of your whole data frame fff <- function( data, rows) { data.1 <- data[1:rows,] get all necessary stuf on data.1 return what you want } You can put a dimension check if you want the function to be more robust Regards Petr r-help-boun...@r-pr

Re: [R] ?max (so far...)

2009-07-02 Thread Duncan Murdoch
On 01/07/2009 9:10 PM, Carl Witthoft wrote: > More generally, you can always write a loop. They aren't necesssrily fast > or elegant, but they're pretty general. For example, to calculate the max > of the previous 50 observations (or fewer near the start of a vector), you > could do >

Re: [R] ?max (so far...)

2009-07-13 Thread Erich Neuwirth
Belated answer: A few remarks regarding your questions: Your running max problem could be solved in the following way: (which is a soution based o Duncan Murdoch's suggestion, but a little bit more general. foldOrbit<-function(x,fun){ res<-numeric(length(x)) res[1]<-x[1]