try this:
x <- c(3, 3, 1)
y <- c("x","h","y")
paste(rep(y, x), unlist(sapply(x, seq_len)), sep = "")
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
Quoting Rory Winston <rory.winston at gmail.com>:
> 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.
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm