Re: [R] Problems plotting a function defined as a product

From: Jacques VESLOT <jacques.veslot_at_good.ibl.fr>
Date: Thu 13 Jul 2006 - 22:49:11 EST

plot(t, sapply(t,g))



Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr


Alessandro Antonucci a écrit :
> In order to define a function f as:
>
>
>>f <- function(x) (x+1)*(x+2)
>
>
> I want to use the notation:
>
>
>>v = c(1,2)
>>g <- function(x) prod((v+x))
>
>
> That apparently works and, for instance,
> the loop:
>
>
>>for (i in 1:100) { print(f(i)-g(i)) }
>
>
> Produces a sequence of zeros.
>
> Nevertheless, if I try to plot
> the function g by:
>
>
>>t = seq(0,100,1)
>>plot(t,g(t),type="l")
>
>
> I obtain the following errors/warning:
>
>
>>Error in xy.coords(x, y, xlabel, ylabel, log) :
>> 'x' and 'y' lengths differ
>>In addition: Warning message:
>>longer object length
>> is not a multiple of shorter object length in: v + x
>>Execution halted
>
>
> Any idea about that?
>
> Kind regards,
> Alessandro
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 13 23:04:43 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 14 Jul 2006 - 00:15:08 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.