[R] From vector to a step function

Greg Snow Greg.Snow at imail.org
Mon Jan 10 22:02:11 CET 2011


?approxfun

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Alaios
> Sent: Monday, January 10, 2011 9:43 AM
> To: r-help at r-project.org
> Subject: [R] From vector to a step function
> 
> Greetings R members.
> 
> I have a few vectors that denote the 'steps' of different step
> functions
> v1=c(3,4,5,1,2,3,4,5)
> v2=c(5,6,2,4,7,3,2,5)
> v3=c(1,2,4,7,3,1,3,5)
> 
> Here v1,v2,v3 are considered as the steps for the f1,f2,f3 step
> functions.
> 
> For example f1 looks like that (step size is always same and fixed)
> 
> f1= 3 (x>=-3,x<-2)
> f1= 4 (x>=-2,x<-1)
> f1= 5 (x>=-1,x<0)
> f1= 1 (x>=0, x<1)
> and so on.
> 
> What I only have are these vectors that are interpreted as functions
> (as shown above, x (step is 1 here). I would like to ask your help of
> how I can create some function that reads one of the vector
> v1,v2,v3.... and returns results that are acceptable by integrate()
> function.
> 
> Usually integrate wants a pre-defined function like
> myfunc(x)<-function{ x^2 }
> but this is not the case here.
> 
> Could you please give me some hints how I can proceed?
> 
> I would like to thank u in advance for your help
> 
> Regards
> Alex
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list