[R] Plotting a function with curve()

Simon Fear Simon.Fear at synequanon.com
Wed Jul 30 16:56:44 CEST 2003

Clue is in the error message ... "an expression containing x". Not y.

curve(x^2, from=0,to=1)

Think of plotting f(x), not calling it y.


-----Original Message-----
From: Damon Wischik [mailto:djw1005 at cam.ac.uk]
Sent: 30 July 2003 15:11
To: R-Help
Subject: [R] Plotting a function with curve()

Why does
> curve(function(y) y^2, from=0,to=1)
not work, whereas
> myf <- function(y) y^2
> curve(myf, from=0,to=1)

For the former, I get the error message
Error in curve(function(y) y^2, from = 0, to = 1) : 
	'expr' must be a function or an expression containing 'x'

I'm using R1.7.0 under Windows XP.

Damon Wischik.

R-help at stat.math.ethz.ch mailing list

Simon Fear
Senior Statistician
Syne qua non Ltd
Tel: +44 (0) 1379 644449
Fax: +44 (0) 1379 644445
email: Simon.Fear at synequanon.com
web: http://www.synequanon.com
Number of attachments included with this message: 0
This message (and any associated files) is confidential and\...{{dropped}}

More information about the R-help mailing list