提取文本中下划线之间的数字 [英] Extract number between underscore in text

查看:67
本文介绍了提取文本中下划线之间的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似名称的文件

  • Hughson.George_54_4
  • Ifran.Dean_51_3
  • Houston.Amanda_49_6

我想创建一个数据框,其中每一行都是从文件名中以作者、卷、问题的形式提取的信息.

I'd like to create a data frame where each row is information extracted from a file name in the form of Author, Volume, Issue.

我能够提取名称和卷,但似乎无法获取问题编号.使用stringr"包,我完成了以下操作,它给了我 _4 而不仅仅是 4.

I'm able to extract the name and volume, but can't seem to get the issue number. Using "stringr" package, I've done the following, which gives me _4 instead of just 4.

[^a-z](?:[^_]+_){0}([^_ ]+$)  

我该如何解决这个问题?

How do I fix this?

推荐答案

您正在寻找:

read.table(text = string, sep ='_', col.names = c('Author', 'Volume', 'Issue'))

          Author Volume Issue
1 Hughson.George     54     4
2     Ifran.Dean     51     3
3 Houston.Amanda     49     6

哪里

string <- c("Hughson.George_54_4", "Ifran.Dean_51_3", "Houston.Amanda_49_6")

您正在寻找:

 read.table(text = string, sep ='_', fill=TRUE)

这篇关于提取文本中下划线之间的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆