R/aprox.r

Defines functions aprox

# My approx function ===============================================
aprox <- function( x, y, x.out ){
  # use this for parameterized line functions
  y.out <- rep(NA, length(x.out))
  
  for( i in 1:length(x.out)){
    if( all(is.na(l.x <- which(x < x.out[i])))  ){
      y.out[i] <- y[1]
      next
    } 
    l.x <- max(l.x)
    
    if( all(is.na(u.x <- which(x > x.out[i])))  ){
      y.out[i] <- y[length(y)]
      next
    } 
    u.x <- min(u.x)
    
    if( any(e.x <- which(x == x.out[i]))){
      y.out[i] <- y[e.x[length(e.x)]]
      next
    }
    
    y.out[i] <- y[l.x] + (y[u.x]-y[l.x])*(x.out[i] - x[l.x])/(x[u.x]-x[l.x])
  }
  y.out
}

Try the SDraw package in your browser

Any scripts or data that you put into this service are public.

SDraw documentation built on May 29, 2017, 6:14 p.m.