'I want to plot for a range of values in my function in R [closed]

I have a function in R that has 3 arguments: a,b,c. The arguents b and c don't change but I want to evaluate the function for a range of values of a, meaning I want a to be 10-1000. I then want to take these values and plot them in R.

Any idea how I can do this?



Solution 1:[1]

If your function is already vectorized (i.e. will take a vector of a values) then

curve(myfunction(a = x, b = 3, c = 2), from = 10, to 1000)

would work. If not, you could do

vc <- Vectorize(myfunction)
curve(vc(a = x, b = 3, c = 2), from = 10, to 1000)

curve() also has an n argument that determines the numbers of points to evaluate in the range (the default is 101).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ben Bolker