R语言中 gsub函数应用于数据框中
001、
r1 <- c("CC","CC","GG","TT") r2 <- c("GG","GG","GC","TT") r3 <- c("CC","GG","GG","TT") dat <- data.frame(r1, r2, r3) ## 测试数据框 dat gsub(pattern = "^.", replacement = "Q", dat) ## 直接替换, 将第一个字符替换为Q apply(dat, 2, function(x){gsub(pattern = "^.", replacement = "Q",x)}) ## 使用apply函数, 以每一列为迭代对象,生成字符向量传递给gsub函数
参考:https://www.csdn.net/tags/NtDaAgwsNzAxMTQtYmxvZwO0O0OO0O0O.html