我应该有这样的输出:
AAAA
AAAG
AAAC
AAAT
AAGA
AAGG
...
Run Code Online (Sandbox Code Playgroud)
我想先用数字做这个,将"A"表示为1,将"G"表示为2,等等......
1111
1112
...
Run Code Online (Sandbox Code Playgroud)
然后将1转换为"A",依此类推.我找到了这个函数expand.grid,但这给了我一个包含4个变量(4列)的数据框,每个变量都有一个数字.
你还有其他想法吗?
提前致谢.
编辑:我的原始答案错误地认为你已经有了索引的向量.要从头开始生成这些字母的所有可能组合的向量,请尝试以下方法:
x <- expand.grid(rep(list(c('A', 'G', 'T', 'C')), 4))
do.call(paste0, x)
Run Code Online (Sandbox Code Playgroud)
你可以这样做chartr.
x <- c(1111, 1112, 1113, 1114, 1121)
chartr('1234', 'AGCT', x)
# [1] "AAAA" "AAAG" "AAAC" "AAAT" "AAGA"
Run Code Online (Sandbox Code Playgroud)