[R] vectors as function input

Daniel Malter daniel at umd.edu
Fri Aug 24 07:51:24 CEST 2012


The function you programed expects you to provide 7 arguments. In the first
case, you explicitly specify each of the seven arguments, i.e., you tell the
function: this is yu, this is yf, and so forth. In the second case, you only
specify 2 arguments, t and par[1,1:16]. So the function thinks that
par[1,1:6] is the second argument to your function and that the third to
seventh arguments are missing. As indicated in the error code, the function
fails when it encounters the first argument for which it cannot grasp input,
which is "yf." In other words, the function does not assume that what you
supply is in order unless you supply in order. Check the simplified example
below.

f<-function(x,y){x*y}

x<-rnorm(100)
y<-rnorm(100)
d<-data.frame(x,y)

f(x,y)
f(d)

So, "d" has become the input for x only, which you can see from the fact
that any of f(d,y), f(d,x), or f(d,d) work, because now we have specified
the second necessary argument (and that argument is conformable by R
standards)

Daniel




--
View this message in context: http://r.789695.n4.nabble.com/vectors-as-function-input-tp4641118p4641154.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list