0
我覺得冠軍是有點混亂刪除向量元素,但在這裏我的問題: 我有2個載體,一個包含一些文本含有一些短語R:從矢量元素
text <- c("this is some text","some elements should be removed", "i hope you can help me with this text element problem")
pattern <- c("text", "some","be")
而現在另一個我想刪除從pattern
這是在文本的所有元素,從而導致矢量
text_result
[1] "this is"
[2] "elements should removed"
[3] "i hope you can help me with this element problem"
我試圖
text_result <- sapply(pattern, function(x) gsub(x, text, replacement =""))
或
text_result <- sapply(text, function(y) sapply(pattern, function(x)gsub(x,y,replacement ="")))
但在這兩種情況下,我收到了大量矩陣
length(pattern)*length(text) elements
在此先感謝!
'GSUB(paste0(模式,塌陷= 「|」), 「」,文)' –
工作得很好,謝謝! –