Friday, May 3, 2013

Sum matrices from a list #R

Mergefiles <- function(FOL, listM){
        path <- getwd()
        setwd(FOL)
        print(length(listM))
        newmatrix <- Reduce('+', listM)
        #add first column names
        newmatrix[,1]<- names(newmatrix)[-1]
        #write file
        write.table(newmatrix,file="mergedmatrixXA.txt",sep="\t", row.names=FALSE, quote=FALSE)
        setwd(path)
}

No comments:

Post a Comment