如何从R中的字符串中删除序列号

时间:2019-04-01 05:54:12

标签: r

如何从R中的文本中删除序列号:

样本数据:

a=data.frame(text=c("1.This can be achieved using xyz method. 2. It consists of various steps. 3. For more details, check this website))

预期结果:

This can be achieved using xyz method. It consists of various steps.
For more details, check this website.

2 个答案:

答案 0 :(得分:1)

我们可以在此处尝试使用sub

input <- "1.This can be achieved using xyz method.  2. It consists of various steps. 3. For more details, check this website"
input <- gsub("\\d+\\.\\s*", "", input)

[1] "This can be achieved using xyz method.  It consists of various steps. For more details, check this website"

答案 1 :(得分:1)

或者使用stringr包和str_remove_all函数

> text <- c("1.This can be achieved using xyz method.  2. It consists of various steps. 3. For more details, check this website")
> stringr::str_remove_all(text, "\\d+\\.\\s?")
[1] "This can be achieved using xyz method.  It consists of various steps. For more details, check this website"