我有一个包含字符行的数据框,例如:
hello my name is sam <U+ab93>
hi i love fast cars <U+e>
my favourite colour is yellow <U+E><U+c><U+60>
如何删除此数据框中没有意义的所有术语?
我尝试了apply(document, 1, function(x) gsub("<[:graph:]>", "", x))
,但它不起作用。
答案 0 :(得分:3)
对于
document = c("hello my name is sam <U+ab93>",
"hi i love fast cars <U+e>",
"my favourite colour is yellow <U+E><U+c><U+60>")
会是,
gsub("<[[:graph:]]+>", "", document )
[:graph:]
不是有效的POSIX char类。
或者,您也可以尝试
gsub("<[^>]*>", "", document)
答案 1 :(得分:3)
使用gsub
text = c("hello my name is sam <U+ab93>" , "hi i love fast cars <U+e>" ,
"my favourite colour is yellow <U+E><U+c><U+60>")
df <- data.frame(DOC = text)
df$DOC <- gsub(df$DOC , pattern = "<.*>", replacement = "")