I'm trying to automate this one part of my R script, but I can't figure out how. Essentially, I have this code:
currentmatrix <- datas[,,i]
data <- as.data.frame(currentmatrix)
#mod #
colnames(data) <- c("in1","in2","in3","in4","in5","in6", "in7", "in8", "in9", "in10", "out") #change depending on number of inputs and add to nnet training
#mod #
nnet <- neuralnet(out~in1+in2+in3+in4+in5+in6+in7+in8+in9+in10, data, hidden=hidden, threshold = threshold, stepmax = 10^7,err.fct = "ce",linear.output = F,likelihood = T)
Now, where I have "in1","in2"
etc, I'd like this to be a variable, so that I can simply reference neuralnet(var,data,hidden=hidden,...)
, instead of typing out the inputs to the function each time I want to change the number of inputs. I'd like, for example, to have a function f
for which f(x)
creates x
strings named in[x]
, and then I could write
colnames(data) <- c(f(x))
and nnet <- neuralnet(out~f_sum,...)
or something similar.
Is there a way to do this? Thanks!