Re: [R] Grouping Matrix by Columns; OHLC Data

2013-09-26 Thread arun
Hi Jake. Sorry, I misunderstood about what you wanted. Instead of this: lapply(split(indx,(indx-1)%%n+1),function(i) mat1[,i]) If I use: res1<- lapply(split(indx,(indx-1)%/%n+1),function(i) mat1[,i]) #or lapply(split(indx, as.numeric(gl(ncol(mat1),n,ncol(mat1,function(i) mat1[,i])  lapp

Re: [R] Grouping Matrix by Columns; OHLC Data

2013-09-26 Thread arun
HI, May be this helps: set.seed(24)  mat1<- matrix(sample(1:60,30*24,replace=TRUE),ncol=24) colnames(mat1)<- rep(c("O","H","L","C"),6) indx<-seq_along(colnames(mat1)) n<- length(unique(colnames(mat1)))  res<- lapply(split(indx,(indx-1)%%n+1),function(i) mat1[,i]) lapply(res,head,2) #$`1` #  O