I am unable to get Vectorizeto work with [, having received the error below. Of help("[")it seems to [have arguments with a name x, iand j- but they do not work when I used them as vectorize.args. Can I do it?
dat <- data.frame(a=1:10, b=11:20, c=21:30)
f <- function(i, j, dat) list(dat[i, j])
mapply(f, list(1:2, 3:4), list(1:2, 2:3), MoreArgs = list(dat=dat))
Vectorize(`[`, c("i", "j"))(x=dat, i=list(1:2, 2:3), j=list(1:2, 2:3))
Error in Vectorize ( [, c ("i", "j")): must indicate formal argument names for 'vectorize'
But this works (with a warning about argument names)
`[`(x=dat, i=1:2, j=1:2)
Also, if I do, it’s normal
Vectorize(`[.data.frame`, c("i", "j"))(dat, list(1:2, 2:3), list(1:2, 2:3))