Re: [R] filling array with functions

From: Jerome Asselin <>
Date: Fri, 22 Apr 2011 13:18:06 -0400

On Fri, 2011-04-22 at 10:02 -0700, derek wrote:
> Hello R,
> I would like to find out how to generate array full of functions. I tried it
> like this:
> fv=array(,dim=c(1,10))
> V=c(1:10)
> for (i in 1:10){
> fv[i]<-function(x)(V[i]-b*a*x) # b, x are constants.
> }
> But it returns:
> "incompatible types (from closure to logical) in subassignment type fix"

You could parse individual expressions.

for (i in 1:10){
fv[i]<-parse(text=paste("function(x)(V[", i, "]-b*a*x)", sep="")) }


Hope this helps. mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 22 Apr 2011 - 17:21:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 24 Apr 2011 - 15:30:33 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive