I tried to use acast
from reshape2
within a self written function, but had the problem that acast did not find the data I send to it.
Here is m
I found a pretty inelegant way to solve the problem using super assignments (<<-
).
Changing the function to the following does the job. But, it is pretty ugly as it creates global variables which remain.
wrap.acast <- function(dat, v1 = 1, v2 = 2) {
dat <<- dat
v1 <<- v1
v2 <<- v2
out <- acast(dat, dat[,v1] ~ dat[,v2])
return(out)
}
I am still very interested in other (less clogging) solutions.
prior to running the function:
> ls()
[1] "wrap.acast" "x" "y"
after running the function:
> ls()
[1] "dat" "v1" "v2" "wrap.acast" "x"
[6] "y"