Hi

Ive looked around but I cant figure out how to do this without a for loop. I have a vector of neural net weights from coef.nnet(), which looks like c(3,3,1). I also have a list of weight prefixes, which are c("x","h","y"). I would like to obtain a vector that looks like c("x1","x2","x3","h1","h2","h3","y1") - i.e. if we think of the numeric weight vector as a matrix B ([1 2 3],[1 2 3], [1 0 0]), its like a paste() of the element in vector A[i] with each element in the row i: B[i][j]. I can see that Ripley & Venables use the following, using seq_len and paste() :

 wts <- object$wts
 wm <- c("b", paste("i", seq_len(object$n[1]), sep=""))
 if(object$n[2] > 0)
 wm <- c(wm, paste("h", seq_len(object$n[2]), sep=""))
 if(object$n[3] > 1)  wm <- c(wm,
 paste("o", seq_len(object$n[3]), sep=""))

Is it possible to compress this to a one-liner?

Cheers
Rory

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to