[R] do.call invoking a function with multiple arguments
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.ac.be
Tue Nov 9 09:59:58 CET 2004
Hi Eric,
you could try it this way:
> tab <- as.data.frame(table(factor(1:10)))
> do.call("paste", c(tab, list(sep=":")))
[1] "1:1" "2:1" "3:1" "4:1" "5:1" "6:1" "7:1" "8:1" "9:1"
"10:1"
since `tab' is already a list
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Eric Lecoutre" <lecoutre at stat.ucl.ac.be>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, November 09, 2004 9:12 AM
Subject: [R] do.call invoking a function with multiple arguments
>
> Hi users,
>
> I am not sure to understand the help page about do.call.
>
> --
> do.call(what, args)
> args: a _list_ of arguments to the function call. The 'names'
> attribute of 'args' gives the argument names.
> --
>
> If we take the following sample data:
>
>
> > (tab=as.data.frame(table(factor(1:10))))
> Var1 Freq
> 1 1 1
> 2 2 1
> 3 3 1
> 4 4 1
> 5 5 1
> 6 6 1
> 7 7 1
> 8 8 1
> 9 9 1
> 10 10 1
>
> I can call "paste" on it:
>
> > do.call("paste",tab)
> [1] "1 1" "2 1" "3 1" "4 1" "5 1" "6 1" "7 1" "8 1" "9 1"
> "10 1"
>
> Now if I want to use ":" as the separator, I guess I should write
>
> > do.call("paste",list(tab,sep=":"))
> [1] "c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" "c(1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1)"
>
> which does not return me what I want.
> Of course, I know there are plenty other ways to achieve my goal but
> this is not the first case I encounter I cant' use "do.call" though
> I think it should be possible.
>
> Could someone bring me an example of such a use?
> basically, my needs are:
>
> do.call("foo",args) args containing primary and extra-arguments to
> pass to "foo".
>
> Best wishes,
>
> Eric
>
>
> Eric Lecoutre
> UCL / Institut de Statistique
> Voie du Roman Pays, 20
> 1348 Louvain-la-Neuve
> Belgium
>
> tel: (+32)(0)10473050
> lecoutre at stat.ucl.ac.be
> http://www.stat.ucl.ac.be/ISpersonnel/lecoutre
>
> If the statistics are boring, then you've got the wrong
> numbers. -Edward Tufte
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list