r - 在R中按块分隔文本文件
问题描述
我有一个文本文件,其数据块由“=”分隔,如下所示。
[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 一次读取我的文本文件块,以“=”分隔,以便我可以在每个块中提取信息?
解决方案
用 读取数据后readLines
,我们可以split
通过list
创建vector
分组变量
i1 <- lines == "="
split(lines[!i1], cumsum(c(TRUE, diff(i1) < 0))[!i1])
数据
lines <- readLines("file.txt")
推荐阅读
- reactjs - 如何为仅将 props 传递给 Child 的组件定义 propTypes
- postgresql - PostgreSQL 在同一个事务中创建视图和导入外部模式
- haskell - 有没有办法让 Haskell 中的“拆分”函数接受两种不同类型的输入?
- .net - 无法生成 cookie Web API
- asynchronous - 使用不同结果类型时,在 dotnet 核心中使用 Task.WhenAll 的最佳实践
- c# - 在 Selenium C# 中使用 xpath 查找 webtable 中的总行数
- unit-testing - 为什么 Spock Framework 建议使用 SUS,但在任何示例中都没有这样的缩写?
- sql-server - 使用 Microsoft SQL Server Management Studio 将 SQL Server 数据库转储(数据和模型)从一个环境传输到另一个环境
- typescript - Joi 验证集合?
- python - Ubuntu 上使用的 PyInstaller - CentOS 上使用的压缩文件 - 错误