如何删除其他字符串之间带有/的数字集? [重复]

问题描述 投票:1回答:3

我需要从通常以一个较大数字报告的文本注释中提取血压值,以较小的数字报告“ /”,其单位为mm HG(不是小数,只能这样写)。在下面的4个示例中,我只想提取114 / 46、135 / 67、109 / 50和188/98,在前后没有空格,并将最高编号放在名为SBP的列中,并将最低编号放在称为SBP的列中DBP。预先感谢您的协助。

bb <- c("PATIENT/TEST INFORMATION (m2): 1.61 m2\n BP (mm Hg): 114/46 HR 60 (bpm)", "PATIENT/TEST INFORMATION:\ 63\n Weight (lb): 100\nBSA (m2): 1.44 m2\nBP (mm Hg): 135/67 HR 75 (bpm)", "PATIENT/TEST INFORMATION:\nIndication: Coronary artery disease. Hypertension. Myocardial infarction.\nWeight (lb): 146\nBP (mm Hg): 109/50 HR (bpm)", "PATIENT/TEST INFORMATION:\nIndication: Aortic stenosis. Congestive heart failure. Shortness of breath.\nHeight: (in) 64\nWeight (lb): 165\nBSA (m2): 1.80 m2\nBP (mm Hg): 188/98 HR 140 (bpm) ")   

BP <- head(bb,4)
dput(bb)
r regex string text-mining
3个回答
1
投票

我们可以使用regmatches/regexpr中的base R提取所需的值,然后使用read.table创建两列data.frame


2
投票

Base R解决方案:


1
投票

您可以使用str_match并选择介于/之间的数字

© www.soinside.com 2019 - 2024. All rights reserved.