【发布时间】:2020-10-06 16:38:29
【问题描述】:
我有一个字符变量。我需要从title="" 值中提取信息。基本上,我需要"" 中的所有值,就在title= 之后。
这是示例数据集:
df <- data.frame(
id = c(1,2,3),
character = c('mrow><mn>2<mn><mi>h<mi><m title="h+r=2"><mstyle',
'mrow><mn>2<mn><mi>h<mi><m title="r+2h=h"><mstyle&',
'mrow><mn>2<mn><mi>h<mi><m title="h∙rleft(frac{2h}{2}right)"><mstyle>'))
> df
id character
1 1 mrow><mn>2<mn><mi>h<mi><m title="h+r=2"><mstyle
2 2 mrow><mn>2<mn><mi>h<mi><m title="r+2h=h"><mstyle&
3 3 mrow><mn>2<mn><mi>h<mi><m title="h·rleft(frac{2h}{2}right)"><mstyle>
我想要的输出是:
> df
id character
1 1 h+r=2
2 2 r+2h=h
3 3 h·rleft(frac{2h}{2}right)
【问题讨论】:
-
within(df, character <- gsub('title="([^"]+)|.', '\\1', df$character))你不需要额外的包