I have a function with many arguments:
fun(A,B,C,D,E)
Now I want to assign fixed value a,b,c,d to A,B,C,D and assign E a list of 1 : 7
I want to use do.call() as below, but it doesn't work.
a <- do.call(function(x) fun(A = a, B = b, C = c, D = d, E = x), list(1:7))
I turn to lapply, and it works,
a <- lapply(c(1:7), function(x) fun(A = a, B = b, C = c, D = d, E = x))
As Joshua Ulrich's answer, when I try
a `<- do.call(fun, list(A = a, B = b, C = c, D = d, E = list(1:7)))`
it says
(list) object cannot be coerced to type 'double'
So I guess fun needs a double value for E, but do.call() doesn't give the values one by one, but a list.
I don't want to use lapply because it returns a list of list, which, if I want to point at a special list, I have to use [[]], and only single value is allowed in [[]], and I cannot use a vector to point at, e.g. [[a]],with a <- c(1:7).
How to make do.call() work?
lapplysince it works? I think you have misunderstood why/how to usedo.call- it is not supposed to do the same thing aslapply... Can you providefunand the desired output? - konvaslapplybut then you can simplify your result, depending on the format you want it to have. For example, you can covert this listx <- list(1, 2, 3)to the vectorc(1, 2, 3)simply byunlist(x). It really depends on the format of the output oflapplyand what you want to convert it to (sapplydoes some automatic simplification which may or may not work for you, I tend to avoid it) - konvaslist(1, 2, 3, 4)[2:3]- konvas