I want to separate characters. Despite the fact that I have a large working frame for work, the following is a small example to show what needs to be done.
mydf <- data.frame (name = c("L1", "L2", "L3"), M1 = c("AC", "AT", NA), M2 = c("CC", "--", "TC"), M3 = c("AT", "TT", "AG"))
I want to split characters for variables M1-M3 (in a real dataset I have> 6000 variables)
name M1a M1b M2a M2b M3a M3b L1 ACCCAT L2 AT - - TT L3 NA NA TCAG
I tried the following codes:
func<- function(x) {sapply( strsplit(x, ""), match, table= c("A","C","T","G", "--", NA))} odataframe <- data.frame(apply(mydf, 1, func) ) colnames(odataframe) <- paste(rep(names(mydf), each = 2), c("a", "b"), sep = "") odataframe
source share