Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 提取R中变量的双引号之间的单词_Regex_R_Stringr_Stringi - Fatal编程技术网

Regex 提取R中变量的双引号之间的单词

Regex 提取R中变量的双引号之间的单词,regex,r,stringr,stringi,Regex,R,Stringr,Stringi,我想从以下输入中提取名称,其形式如括号中所示 # Example of the input in brackets('name":"Tale") name<- c('name":"Tale"','name":"List"') 将向量转换为一列data.frame,然后使用gsub从字符串中删除名称“:和” 例如: transform(data.frame(name), name = gsub("name\":|\"", "", name)) ## name ## 1 Tale ##

我想从以下输入中提取名称,其形式如括号中所示

# Example of the input in brackets('name":"Tale")
name<- c('name":"Tale"','name":"List"')

将向量转换为一列
data.frame
,然后使用
gsub
从字符串中删除
名称“:

例如:

transform(data.frame(name), name = gsub("name\":|\"", "", name))
##   name
## 1 Tale
## 2 List

我们可以使用
stri\u extract\u last\u单词

library(stringi)
library(data.table)
setDT(list(name=stri_extract_last_words(name)))[]
#   name
#1: Tale
#2: List

从昨天起,我又开始阅读stringi手册。像往常一样,你跑得太快了。:)@爵士乐感谢您的评论和投票。这个软件包中有很多方便的函数。是的,我一直在使用其中的一些函数来处理数据集的字符串提取。速度很快。
library(stringi)
library(data.table)
setDT(list(name=stri_extract_last_words(name)))[]
#   name
#1: Tale
#2: List