从R中两个符号之间的段落中提取文本

布莱恩·亚当斯(Bryan Adams)

我有一段文字,我想从中提取每个样本大小。我通常可以让Regex正常工作,但我无法。

这是一个例子:

x = "OBJECTIVES:

In diabetic polyneuropathy (DPN) patients, the effect of folic acid and homocysteine has been related to components of nerve conduction velocity (NCV). The objective of this study was to determine the effect of folic acid supplementation on NCV in DPN patients.
METHODS:

Patients were randomized to receive either 1 mg of folic acid (n = 40) or placebo (n = 40) for 16 weeks. Blood samples were collected to assess serum folic acid and homocysteine concentrations, and NCV was performed for assessment of diabetic neuropathy.
RESULTS:

At 16 weeks, in the supplemented group, serum levels of folic acid (p < 0.001) increased, homocysteine concentrations decreased (p < 0.001), with no change in serum vitamin B12 levels. There was a significant increase in sensory sural amplitude (p < 0.001), and components of motor nerves, including amplitude (p = 0.001) and velocity (p < 0.001), but decreased onset latency of peroneal (p = 0.019) and tibial (p = 0.011) motor nerves.
CONCLUSION:

Our data suggest that supplementation with 1 mg of folic acid for 16 weeks may be useful for enhancing NCV in DPN patients."

我想提取两个样本大小。在这种情况下,n = 40,n = 40。

我试过了

gsub('.*[n=]|).*','',x)

我回来 ts.

安德鲁

您可以stringr提取“ n =”后接至少一位数字。假设等号的两边都没有空格或一个空格:

library(stringr)
str_extract_all(x, "n\\s?\\=\\s?\\d+")
[[1]]
[1] "n = 40" "n = 40"

编辑:以下应mutate与您的其他条件一起使用。我从切换到stringrstringi以获取NA没有匹配项的字符串。另外,您可以使用paste代替,stri_flatten但我坚持使用,stri_flatten因为它保留NA为缺少的值,而不是"NA"字符一样的字符paste

sapply(stri_extract_all(x, regex = "n\\s?\\=\\s?\\d+"), stri_flatten, collapse = ", ")

对于正则表达式,我从R的备忘单开始(仍然参考它)。上面的正则表达式的工作原理如下:

n -字母n

\\s?-最多1个(the ?)space(\\s)(*?--your调用相比,您可能更喜欢MrFlick的使用

\\= -等号

\\s?-最多1(the ?)个空格(\\s

\\d+-一个或多个(+)个数字(\\d

资料

x = c("OBJECTIVES:

In diabetic polyneuropathy (DPN) patients, the effect of folic acid and homocysteine has been related to components of nerve conduction velocity (NCV). The objective of this study was to determine the effect of folic acid supplementation on NCV in DPN patients.
METHODS:

Patients were randomized to receive either 1 mg of folic acid (n = 40) or placebo (n = 40) for 16 weeks. Blood samples were collected to assess serum folic acid and homocysteine concentrations, and NCV was performed for assessment of diabetic neuropathy.
RESULTS:

At 16 weeks, in the supplemented group, serum levels of folic acid (p < 0.001) increased, homocysteine concentrations decreased (p < 0.001), with no change in serum vitamin B12 levels. There was a significant increase in sensory sural amplitude (p < 0.001), and components of motor nerves, including amplitude (p = 0.001) and velocity (p < 0.001), but decreased onset latency of peroneal (p = 0.019) and tibial (p = 0.011) motor nerves.
CONCLUSION:

Our data suggest that supplementation with 1 mg of folic acid for 16 weeks may be useful for enhancing NCV in DPN patients.", "no numbers here", "n = 100")

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

从PowerShell中的Shell命令中提取两个关键词之间的多行文本

来自分类Dev

在Perl中提取两个关键字之间的段落

来自分类Dev

R:如何从两个关键词之间的文本中提取信息并导出到表格?

来自分类Dev

提取熊猫列中两个标记之间的文本

来自分类Dev

R中两个逗号之间的文本数据的正则表达式提取

来自分类Dev

提取两个P之间的文本

来自分类Dev

从两个词之间提取文本

来自分类Dev

提取两个行号之间的文本

来自分类Dev

隔离R中两个符号之间的数字

来自分类Dev

使用VBA从两个相同字符之间的字符串中提取文本

来自分类Dev

如何使用sed提取两个条形符号(即“ |”)之间的文本?

来自分类Dev

R /考试:防止在两次考试中的两个段落之间出现分页符

来自分类Dev

从文件中提取两个模式之间的线

来自分类Dev

在JavaScript中提取两个特殊字符之间的字符

来自分类Dev

在Excel中提取两个不同字符之间的数据

来自分类Dev

如何获得R中两个单词之间的文本?

来自分类Dev

如何提取两个符号之间的值?

来自分类Dev

从bash中两个给定位置之间的文件中提取片段

来自分类Dev

提取字符串中两个符号之间的所有内容

来自分类Dev

提取字符串中两个符号之间的所有内容

来自分类Dev

使用 Perl 从日志文件中逐行提取两个符号之间的数据

来自分类Dev

Python-如何在大文本中的两个变量之间提取文本

来自分类Dev

从两个匹配模式之间的文件中提取内容(仅从文件中提取HTML)

来自分类Dev

如何避免并排的两个段落中的文本重叠

来自分类Dev

使用.bat提取两个单词之间的文本

来自分类Dev

提取两个单词之间的文本,多行验证

来自分类Dev

使用.bat提取两个单词之间的文本

来自分类Dev

SimpleXML提取两个标签之间的文本

来自分类Dev

如何提取位于两个指标之间的文本?

Related 相关文章

  1. 1

    从PowerShell中的Shell命令中提取两个关键词之间的多行文本

  2. 2

    在Perl中提取两个关键字之间的段落

  3. 3

    R:如何从两个关键词之间的文本中提取信息并导出到表格?

  4. 4

    提取熊猫列中两个标记之间的文本

  5. 5

    R中两个逗号之间的文本数据的正则表达式提取

  6. 6

    提取两个P之间的文本

  7. 7

    从两个词之间提取文本

  8. 8

    提取两个行号之间的文本

  9. 9

    隔离R中两个符号之间的数字

  10. 10

    使用VBA从两个相同字符之间的字符串中提取文本

  11. 11

    如何使用sed提取两个条形符号(即“ |”)之间的文本?

  12. 12

    R /考试:防止在两次考试中的两个段落之间出现分页符

  13. 13

    从文件中提取两个模式之间的线

  14. 14

    在JavaScript中提取两个特殊字符之间的字符

  15. 15

    在Excel中提取两个不同字符之间的数据

  16. 16

    如何获得R中两个单词之间的文本?

  17. 17

    如何提取两个符号之间的值?

  18. 18

    从bash中两个给定位置之间的文件中提取片段

  19. 19

    提取字符串中两个符号之间的所有内容

  20. 20

    提取字符串中两个符号之间的所有内容

  21. 21

    使用 Perl 从日志文件中逐行提取两个符号之间的数据

  22. 22

    Python-如何在大文本中的两个变量之间提取文本

  23. 23

    从两个匹配模式之间的文件中提取内容(仅从文件中提取HTML)

  24. 24

    如何避免并排的两个段落中的文本重叠

  25. 25

    使用.bat提取两个单词之间的文本

  26. 26

    提取两个单词之间的文本,多行验证

  27. 27

    使用.bat提取两个单词之间的文本

  28. 28

    SimpleXML提取两个标签之间的文本

  29. 29

    如何提取位于两个指标之间的文本?

热门标签

归档