Hello,
I didn't know rep_vec couldn't be modified, I thought vec was the main
vector.
Revised.
vec = c("1","2","3","-","-","-","4","5","6","1","2","3","-","-","-")
rep_vec = rep(vec,times=20)
nms = c("A","B","C","D")
rv <- sapply(split(rep_vec, cumsum(rep(c(1, 0, 0), length(rep_vec)/3))),
pas
I'm checking out Phil's solution...so far so good. Thanks! Yes, 25 not 5
rows, sorry about that.
Rui - I can't modify rep_vec...that's just sample data. I have to start
with rep_vec and go from there.
have a good weekend all...
Ben
On Fri, Jun 15, 2012 at 2:51 PM, Rui Barradas wrote:
> Hello
Hello,
Try
vec = c("1","2","3","-","-","-","4","5","6","1","2","3","-","-","-")
nms = c("A","B","C","D")
rep_vec <- rep(sapply(split(vec, cumsum(rep(c(1, 0, 0), 5))), paste,
collapse=""), 4)
mat <- matrix(rep_vec, nrow=5, byrow=TRUE, dimnames=list(NULL,nms))
mat
Hope this helps,
Rui Barrad
Ben -
There are most likely faster ways, but
matrix(apply(matrix(rep_vec,ncol=3,byrow=TRUE),1,paste,collapse=''),
ncol=4,byrow=TRUE,dimnames=list(NULL,nms))
seems reasonably fast. (Do you really mean 4 columns and *5* rows?
With rep_vec = rep(vec,times=20), I get 25 rows.)
Hello,
What is the fastest way to do this? I has to be done quite a few times.
Basically I have sets of 3 numbers (as characters) and sets of 3 dashes and
I have to store them in named columns. The order of the sets and the column
name they fall under is important. The actual numbers and the patte
5 matches
Mail list logo