[R] User's function

Phil Spector spector at stat.berkeley.edu
Fri Dec 4 19:47:56 CET 2009


Lisa -
    I think this is what you're looking for:

myfunction = function(...)do.call(cbind,list(...))


 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Fri, 4 Dec 2009, Lisa wrote:

>
> Thank you for your reply. But this is not what I want.
>
> For example, I have several variables, like
>
> arg1 <- c(1, 2, 3, 5, 6, 6)
> arg2 <- c(3, 1, 5, 5, 7, 8)
> arg3 <- c(8, 10, 4, 0, 9, 1)
> arg4 <- c(11, 22, 30, 5, 61, 22)
>>
> I just want to bind some of these variables based on the arguments assigned
> in myfunction()
>
> myfunction <- function(arg1, arg2, arg3, …)
> { 
> x <- cbind(arg1, arg2, arg3, …)
> }
>
> myfunction(arg1, arg2, arg3, …)
>
> If I assign 2 arguments, the function can bind those two arguments, or if I
> assign 3 arguments, the function can bind those three arguments, and so on.
>
> Lisa
>
>
>
> baptiste auguie-5 wrote:
>> 
>> Hi,
>> 
>> try ?do.call
>> 
>> do.call(cbind, replicate(3, 1:10, simplify=FALSE))
>> 
>> HTH,
>> 
>> baptiste
>> 
>> 2009/12/4 Lisa <lisajca at gmail.com>:
>>>
>>> Hello, All,
>>>
>>> I want to write a function to do some works based on the arguments. For
>>> example, bind some variables (arguments) as this:
>>>
>>> myfunction <- function(arg1, arg2, arg3, …)
>>> {
>>>  x <- cbind(arg1, arg2, arg3, …)
>>> }
>>>
>>> myfunction(arg1, arg2, arg3, …)
>>>
>>> The function can automatically determine the number of arguments and bind
>>> them, which means if I assign 2 arguments, the function can bind those
>>> two
>>> arguments, or if I assign 3 arguments, the function can bind those three
>>> arguments, and so on. Here assume the arguments are all continuous
>>> variables
>>> and have the same length. Is it possible?
>>>
>>> I would appreciate if some one can help me. Thanks!
>>>
>>> Lisa
>>>
>>> --
>>> View this message in context:
>>> http://n4.nabble.com/User-s-function-tp948737p948737.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> R-help at 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.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>> 
>> ______________________________________________
>> R-help at 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.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> 
>
> -- 
> View this message in context: http://n4.nabble.com/User-s-function-tp948737p948763.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.html
> and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list