[R] do.call invoking a function with multiple arguments
Eric Lecoutre
lecoutre at stat.ucl.ac.be
Tue Nov 9 09:12:54 CET 2004
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
More information about the R-help
mailing list