我有一个文本文件,其数据块之间用“ =”分隔,如下所示。
[976] "="
[977] "PRIMER_LEFT_EXPLAIN=considered 140, low tm 139, ok 1"
[978] "PRIMER_RIGHT_EXPLAIN=considered 6983, GC content failed 251, low tm 5602, high tm 166, high any compl 27, high end compl 263, long poly-x seq 30, ok 644"
[979] "PRIMER_INTERNAL_OLIGO_EXPLAIN=considered 10049, overlap excluded region 47, GC content failed 248, low tm 4152, high tm 2589, high any compl 5, long poly-x seq 46, ok 2962"
[980] "PRIMER_PAIR_EXPLAIN=considered 644
[981] "="
如何让R一次以“ =”分隔读取文本文件块,以便可以提取每个块中的信息?
答案 0 :(得分:1)
使用readLines
读取数据后,我们可以通过创建分组变量来split
到list
中的vector
个
i1 <- lines == "="
split(lines[!i1], cumsum(c(TRUE, diff(i1) < 0))[!i1])
lines <- readLines("file.txt")