If a function takes a data frame as one of it's arguments, is it possible to vectorize it? I have a custom function which takes the following arguments:
a.function<- function(a=c(),
b=data.frame(),
c=data.frame(),
d="",
e="",
f=data.frame()) {
...
}
Is there a data structure I could use which would allow me to use one of the *apply functions, so that I could run the function on many variables at once?
EDIT: Here's an example of how I'm currently running the code:
a <- c(1000,2000,1000)
b <- data.frame(type=c('string1',
'string2',
'string3'),
value=c(2500,4000,3500),
difference=c(0,30,0))
c <- data.frame(pd=4,
gu=100)
d <- 'string4'
e <- 8
test <- a.function(a, b, c, d, e)
# test is a 1x3 character matrix
> test
[1] "44537" "0.1" "B"
Together, a, b, c, d, and e describe a single group, and I run a.function on that group.. I would like to be able to define numerous such groups and then run a.function on all those groups at once. I realize I may need to significantly refactor the code; that's fine. Thanks!
sinorpaste.abcdandeare the different data frames (and other data types), and I want to applya.functionto them. I'm looking for a data structures solution. Joran mentioned lists below, I'll try that; if there are other methods of vectorizing, please let me know.