Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (50.2k points)

I'd like to plot something like this:

plot(dnorm(mean=2),from=-3,to=3)

But it doesn't work as if you do:

plot(dnorm,from=-3,to=3)

Can you please guide me where I am wrong?

1 Answer

0 votes
by (108k points)

Try to implement the below code in R programming:

curve(dnorm(x, mean = 2), from = -3, to = 3)

The above curve function watches for the xname= variable (defaults to x) in the function call, so in dnorm(x, mean=2), it is not able to refer to an x in the calling environment, it is a placeholder for the curve to use for repeated values.

The reason plot(dnorm, ...) works because of the presence of graphics::plot.function, since dnorm in our case, is a function. When you have tried to execute the plot(dnorm(mean=2)), the dnorm(mean=2) will no longer a function, it is a call ... that happens to fail because it requires x (its first argument) be provided.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...