r - 根据模式将字符串拆分为列
问题描述
33467389|t|Immune Therapies for Hematologic Malignancies.
33467389|a|The era of immunotherapy for hematologic malignancies began with the first allogeneic hematopoietic stem cell transplant (HSCT) study published by E [...].
33477248|t|Unraveling the Role of Innate Lymphoid Cells in AcuteMyeloid Leukemia.
33477248|a|Over the past 50 years, few therapeutic advances have been made in treating.
这是我在我的文件中反复出现的模式。
ID 是一个数字,例如33467389
是|t|
论文的标题。同样33467389|a|
,这表示论文的摘要 ID。
lines <- readLines("output_1/Gemtuzumab_Adult/G1.txt")
所以我读这样的文件
所以这种模式贯穿了我的文字。有没有办法把它分成列
ID Abstract
33467389 The era of immunotherapy for hematologic malignancies
解决方案
这里使用sub
的是一个基本的 R 选项:
df$ID <- sub("\\|.*$", "", df$text)
df$Abstract <- sub("^.*\\|", "", df$text)
df[, c("ID", "Abstract")]
ID Abstract
1 33467389 Immune Therapies for Hematologic Malignancies.
2 33467389 The era of immunotherapy for hematologic malignancies began with the first allogeneic hematopoietic stem cell transplant (HSCT) study published by E [...].
3 33477248 Unraveling the Role of Innate Lymphoid Cells in AcuteMyeloid Leukemia.
4 33477248 Over the past 50 years, few therapeutic advances have been made in treating.
推荐阅读
- .net-core - 如何告诉 Swashbuckle 5 在 dotnetcore 3.0 中需要正文内容?
- bash - bash 读取:`vs.txt':不是有效的标识符
- javascript - 错误 - 对象作为 React 子项无效
- javascript - 为什么 ` 与 JavaScript 中的 ' 不同?
- java - 如何将活动 UI 的点击传递到地图片段以将地图更改为 MAP_TYPE_HYBRID
- c# - C# Selenium Chrome 单击默认 chrome 主页中的链接
- amazon-web-services - 由于不同的安全组,无法创建极光 RDS 数据库集群
- javascript - Jquery 数据表销毁
- sql-server - 避免将特定值插入到 sql 表中
- javascript - 是否可以在对象内格式化日期?