Downsampling excessively sampled curves I'm looking for a quick (event if not so accurate) way to deal with over-sampled curves using R. Consider the following example in which x contains 1000 values in the range [0, 1) and y is some function of x.
x <- sort(runif(1000))
y <- sin(x)

I'm looking for a way to take only 100 points on this curve, preferably in equal intervals, without knowing the actual model that produces y's from x's. My naiive approach is to find indices of original x values that are closest to the new ones:
x.new <- seq(0, 1, 0.01)
y.new <- c()
for(x.val in x.new){
  ix <- which.min((x.val - x) ** 2) #closest value in x
  y.new <- c(y.new, y[ix])
}

Or, using a sapply
find.closest.y <- function(v){
  return(y[which.min((v - x)**2)])
}

y.new <- sapply(x.new, find.closest.y)

I'm OK with the accuracy of this method, but I suspect that there is a way to acheive this using functions from standard R libraries. Am I right? Is there a simpler method to downsample curves?
 A: There are bunches of good algorithms to do that. They are known as
data compression algorithms, and are widely used for biomedical data
such as EEG. I recommend the fan algorithm which while being fairly simple
gives nice results in many situations. It does not seem to be available 
in R packages but is easily implemented.  See e.g a course by Carlos E. Davila,
lyle.smu.edu/~cd/EE5345/lect11_spr00.PDF
Most data compression algorithms work on regularly sampled signal $x_t$ 
and build online an irregular sampling at a low cost. Some run ex post 
with a small delay, as the fan algorithm do.
For purely graphics purpose there are very efficient methods based on
Bezier Splines, which are natively supported by some graphical languages
as pdf or SVG. Goggle searches may bring you what you need.
A: I believe the keyword you're looking for is "interpolation". A default R install has the function 'loess', which may fit the bill. Also 'smooth.spline' and 'spline'. Package 'akima' has 'aspline'. Etc.
A: Wouldn't an average of the two nearest values be a better estimate for y.new[ix] than 
  y.new <- c(y.new, y[ix])

Perhaps even a lever arm weighted average depending on how relatively near    x.val     is to the two nearest points? 
