Dear Jim Holtman,
I would like to thank you for your help.
Just to update also the community that worked fine :)
Best Regards
Alex
--- On Mon, 1/10/11, jim holtman wrote:
> From: jim holtman
> Subject: Re: [R] From vector to a step function
> To: "Alaios"
> Cc: r-hel
2011 9:43 AM
> To: r-help@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
try this:
> f.main <- function(vec){
+ breaks <- seq(-3, by = 1, length = length(vec) + 1L)
+ function(x){
+ indx <- findInterval(x, breaks)
+ vec[indx]
+ }
+ }
> f1 <- f.main(c(3,4,5,1,2,3,4,5))
> f2 <- f.main(c(5,6,2,4,7,3,2,5))
> f3 <- f.main(c(1,2,4,7,3,1,3,5))
>
>
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
4 matches
Mail list logo