Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按顺序计数字符,忽略给定字符(R)_R_String_Vector_Count - Fatal编程技术网

按顺序计数字符,忽略给定字符(R)

按顺序计数字符,忽略给定字符(R),r,string,vector,count,R,String,Vector,Count,我有一个单字符串向量: seq <- c("c","t","c","t","c","c","t","a","t", "g", "g", "c", "g", "g", "g", "a", "a", "g", "c", "-", "-", "a", "a","-", "-", "-", "c", "t", "g") seq这很简单: res <- rep(NA_integer_, length(seq)) res[seq != "-"] <- seq(from = 1000, b

我有一个单字符串向量:

seq <- c("c","t","c","t","c","c","t","a","t", "g", "g", "c", "g", "g", "g", "a", "a", "g", "c", "-", "-", "a", "a","-", "-", "-", "c", "t", "g")
seq这很简单:

res <- rep(NA_integer_, length(seq))
res[seq != "-"] <- seq(from = 1000, by = 1, length.out = sum(seq != "-"))

res这感觉像是一个几乎肯定已经在为生物序列设计的软件包中解决了的问题,例如Bioconductor的Biostring。尽量避免使用同样是函数的变量名,如
seq
res <- rep(NA_integer_, length(seq))
res[seq != "-"] <- seq(from = 1000, by = 1, length.out = sum(seq != "-"))