This an alternating way of doing it using a list if you know the
argument names in
the function definition i.e. ?formals and ?alist, But would change
the default values of the function. Probably not you wanted.
> f <- function(x,y,z) x+y+z
> args<-alist(x=5,y=6,z=7)
> formals(f) <- args
> f()
[1]
How about (assuming the variables you defined):
ms <- matrix(unlist(vs), ncol=2,byrow=TRUE)
m[ms]
---
Jeff NewmillerThe . . Go Live...
DCN:Basics: ##.#. ##.#. Live Go.
vector as multiple parameters (as in python f(*x))
Thanks Bert, do.call is exactly what I was looking for. What in lisp
is apply and in python f(*v).
> Your whole premise that the arguments of a function should be mappable to
> elements of a vector seems contrary to good R programming practice.
> Jeff I didn't pretend to imply that the mapping should by always
s/by always/always be/
Sorry.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.h
Thanks Bert, do.call is exactly what I was looking for. What in lisp
is apply and in python f(*v).
> Your whole premise that the arguments of a function should be mappable to
> elements of a vector seems contrary to good R programming practice.
Jeff I didn't pretend to imply that the mapping sho
Your whole premise that the arguments of a function should be mappable to
elements of a vector seems contrary to good R programming practice. Consider
changing the called function's handling of arguments instead to accept the
vector of data directly if a vector makes sense, or to a list if the a
Well, of course the answer is yes (it always is!). I'm just not sure
what the question is.
However, I believe you want something like
do.call(the_function, parameter_list).
?do.call ## for details.
Note that if v is really a (named) vector, it can be converted to a
list via as.list().
Cheers,
Hi,
I want to know if it's possible to pass a vector v=c(x,y,...) to a
function f(x,y,...) so that each vector element corresponds to a
formal argument of the function. For python programmers: f(*v).
Specifically, what I'm trying to achieve is: given a list of
coordinates l=list(c(x1,y1,z1), c(x2
8 matches
Mail list logo