Re: [R] Apply function to every 20 rows between pairs of columns in a matrix

2013-11-11 Thread arun
HI, set.seed(25) dat1 <- as.data.frame(matrix(sample(c("A","T","G","C"),46482*56,replace=TRUE),ncol=56,nrow=46482),stringsAsFactors=FALSE)  lst1 <- split(dat1,as.character(gl(nrow(dat1),20,nrow(dat1 res <- lapply(lst1,function(x) sapply(x[,1:8],function(y) sapply(x[,9:56], function(z)

Re: [R] Apply function to every 20 rows between pairs of columns in a matrix

2013-11-11 Thread arun
Hi, May be this what you wanted. res2 <- lapply(row.names(res[[1]]),function(x) do.call(rbind,lapply(res,function(y) y[match(x, row.names(y)),])))  length(res2) #[1] 48  dim(res2[[1]]) #[1] 2325    8 A.K. On Monday, November 11, 2013 10:20 PM, Yu-yu Ren wrote: Thank you so much for that scr

Re: [R] Apply function to every 20 rows between pairs of columns in a matrix

2013-11-11 Thread arun
HI, It's not very clear. set.seed(25) dat1 <- as.data.frame(matrix(sample(c("A","T","G","C"),46482*56,replace=TRUE),ncol=56,nrow=46482),stringsAsFactors=FALSE)  lst1 <- split(dat1,as.character(gl(nrow(dat1),20,nrow(dat1 res <- lapply(lst1,function(x) sapply(x[,1:8],function(y) sapply(x[,9:56]