Reputation: 2589
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?
Upvotes: 2
Views: 516
Reputation: 32391
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)
Upvotes: 2