Create a list of functions from a vector of characters

后端 未结 3 1479
醉酒成梦
醉酒成梦 2021-01-12 08:12

Thanks in advance, and sorry if this question has been answered previously - I have looked pretty extensively. I have a dataset containing a row of with concatenated informa

3条回答
  •  抹茶落季
    2021-01-12 09:00

    Just to add onto joran's answer, this is what finally worked:

    test.data <- matrix(data=rep(1,25),5,5)
    test.data <- data.frame(test.data)
    
    test.func <- c("x","x+1","x+2","x+3","x+4")
    func.list <- list()
    
    for(i in 1:length(test.func)){
      func.list[[i]] <- function(x){}
      body(func.list[[i]]) <- parse(text=test.func[i])
    }
    
    processed <- mapply(do.call,func.list,lapply(test.data,list))
    

    Thanks again, joran.

提交回复
热议问题