在 R 中的符号后提取文本 [英] Extract text after a symbol in R

查看:72
本文介绍了在 R 中的符号后提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sample1 = read.csv("pirate.csv")
sample1[,7] 
[1] >>xyz>>hello>>mate 1
[2] >>xyz>>hello>>mate 2
[3] >>xyz>>mate 3
[4] >>xyz>>mate 4
[5] >>xyz>>hello>>mate 5
[6] >>xyz>>hello>>mate 6

我必须提取并创建一个数组,其中包含最后一个 >> 之后的所有单词.

I have to extract and create an array which contains all the words after last >>.

如何做到这一点?

另外,如何从以下字符串中提取不同变量中的 (a) o qwerty、(b) mate1 和 (c)pirate1

Also, How can I extract (a) o qwerty, (b) mate1 and (c) pirate1 in different variables from the following string

p= '>>xyz- o qwerty>>hello>>mate1>>sole pirate1'

谢谢

推荐答案

x <- c('>>xyz>>hello>>mate 1', '>>xyz>>hello>>mate 2', '>>xyz>>mate 3', ' >>xyz>>mate 4' ,'>>xyz>>hello>>mate 5')
sub('.*>>', '', x)
#[1] "mate 1" "mate 2" "mate 3" "mate 4" "mate 5"

这篇关于在 R 中的符号后提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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