Take the tour ×  I have a large real 1-d data set called r. I
would like plot:   mean(log(1+a*r)) vs a, with a > -1 .   How
can i do this?  share|improve this question add comment  1
Answer  up vote 2 down vote accepted  You can use sapply to
evaluate the function on a set of values.  x <-
seq(-1,1,length=20) y <- sapply(x, function(a) mean(log(1+a*r))
) plot(x,y, type="l")  Alternatively, you can define a function
to compute this quantity and use curve to plot it. The function
has to be vectorized.  r <- runif(100) f <- function(a)
mean(log(1+a*r)) f <- Vectorize(f) curve(f, xlim=c(-1,1), las=1)
share|improve this answer Vincent you are the king of R :) – 
emanuele Mar 28 '12 at 9:38 How can i do with two data set r'
and r'' and with two parameters a,b? namely
mean(log(1+a*r'+b*r'')) vs a,b –  emanuele Apr 5 '12 at 16:28 To
plot a function of two variables, you can use persp, image,
contour (or levelplot, contourplot in the lattice package). To
build the data, you can use outer and Vectorize. –  Vincent Zoon