[R] Compact sums in functions definitions
Alessandro Antonucci
alessandro at idsia.ch
Thu Jun 15 18:55:15 CEST 2006
I'm trying to make more compact the definition
of a function as for example:
f <- function(x) 2/x+3/x
by simply defining the array of coefficients
arr = c(2,3)
and setting:
g <- function(x) sum((arr/x))
Everything seems to work fine because the values returned
by f and g result coincident for different values of their
argument, but when I try to plot the function g using:
x = seq(-1,1,.01)
plot(x,g(x))
I receive the errors/warnings:
>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: b/t
>Execution halted
Any idea about that?
Thanks.
Alessandro
--
============================================================
Alessandro Antonucci
Dalle Molle Institute for Artificial Intelligence (IDSIA)
at Idsia e-mail: alessandro at idsia.ch
Galleria 2 web: idsia.ch/~alessandro
Via Cantonale mobile: +39 339-567-23-28
CH-6928 tel: +41 58-666-66-69
Manno - Lugano fax: +41 58-666-66-61
Switzerland skype: alessandro.antonucci
More information about the R-help
mailing list