[R] Vector Product question

From: Rory Winston <rory.winston_at_gmail.com>
Date: Sun, 25 May 2008 14:42:35 +0100


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_at_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. Received on Sun 25 May 2008 - 13:44:29 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 25 May 2008 - 16:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive