Re: [R] Pass vector as multiple parameters (as in python f(*x))

2013-01-26 Thread Suzen, Mehmet
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]

Re: [R] Pass vector as multiple parameters (as in python f(*x))

2013-01-25 Thread Jeff Newmiller
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.

Re: [R] Pass vector as multiple parameters (as in python f(*x))

2013-01-25 Thread arun
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.

Re: [R] Pass vector as multiple parameters (as in python f(*x))

2013-01-25 Thread Carlos Pita
> 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

Re: [R] Pass vector as multiple parameters (as in python f(*x))

2013-01-25 Thread Carlos Pita
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

Re: [R] Pass vector as multiple parameters (as in python f(*x))

2013-01-25 Thread Jeff Newmiller
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

Re: [R] Pass vector as multiple parameters (as in python f(*x))

2013-01-25 Thread Bert Gunter
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,

[R] Pass vector as multiple parameters (as in python f(*x))

2013-01-25 Thread Carlos Pita
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