Re: [R] Pasting function arguments and strings

2010-10-13 Thread William Dunlap
unction(x) "the p test" > f("m", 17) [1] "the m test" Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Manta > Sent: We

Re: [R] Pasting function arguments and strings

2010-10-13 Thread Peter Langfelder
>From what I read, you want something like this: myfunction<-function(dataset,arg1,arg2) { func = match.fun(arg2) argument = dataset[, match(paste(arg1,"_test", sep=""), names(dataset))] result=func(argument) return(result) } On Wed, Oct 13, 2010 at 9:28 AM, Manta wrote: > > Thaks for your q

Re: [R] Pasting function arguments and strings

2010-10-13 Thread Manta
Thaks for your quick reply Bert, although I doubt it works. The reason is that the names of the objects of the dataset, all end with the sufix '_test' and therefore I need to attach/paste/glue this suffix to the 'arg2' of the function. Any other idea? -- View this message in context: http://r.7

Re: [R] Pasting function arguments and strings

2010-10-13 Thread Bert Gunter
If I understand you correctly, just arg2(arg1) will work fine...One of the nice features of R. Example: f <- function(dat,fun=mean,...) { fun(dat, ...) ## ... allows extra arguments to fun } f( rnorm(10), trim=.05) ## trimmed mean x <- 1:10 f(x, fun = max,na.rm=TRUE) Cheers, Bert On Wed,

[R] Pasting function arguments and strings

2010-10-13 Thread Manta
Dear R community, I am struggling a bit with a probably fairly simple task. I need to use some already existing functions as argument for a new function that I am going to create. 'dataset' is an argument, and it comprises objects named 'mean_test', 'sd_test', 'kurt_test' and so on. 'arg1' tells