It took me a day to make the sense of Jim's code :(

Hope my comments will help.

## Transform data to matrix
x <- as.matrix(x)

## Apply function to each row
## Create a function to rearrange bases
result <- apply(x, 1, function(eachrow){

## Split each gene to bases
## Exclude the fist column which is id
        bases <- strsplit(eachrow[-1], '')
        
## Transform list to matrix
## Because the result of function strsplit is a list
        bases <- do.call(rbind,bases)
        
## Recombine bases by connecting all bases in each column
        recombine <- apply(bases, 2, paste, collapse="")
        
## Add id
## Transpos recombine
        cbind(eachrow[1], t(recombine))
 })

## Transpose the result matrix  
result <- t(result)

-----
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/sample-and-rearrange-tp2222747p2223594.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

Reply via email to