删除 R 中的单引号

Removing single quotes in R

我正在为 kaggle 上的一个项目制作一些词云,但这行代码不起作用。我正在尝试从包含文本的列中删除所有撇号。在我的语料库中,“'s”和“'”是我最常使用的两个“词”。虽然数据仍然是数据框的形式,但我一直在使用这行代码 df$col <- gsub("\'","", df$col).

下面是一些示例数据。在我的 kaggle 项目中,文本数据位于数据框的一列中。我错过了什么吗?我也试过 str_replace_allsub.

编辑: dput(head(df))

structure(list(X1 = c(0, 1, 2, 3, 4, 5), Character = c("Michael", 
"Jim", "Michael", "Jim", "Michael", "Michael"), Line = c("All right Jim. Your quarterlies look very good. How are things at the library?", 
"Oh, I told you. I couldn’t close it. So…", "So you’ve come to the master for guidance? Is this what you’re saying, grasshopper?", 
"Actually, you called me in here, but yeah.", "All right. Well, let me show you how it’s done.", 
"[on the phone] Yes, I’d like to speak to your office manager, please. Yes, hello. This is Michael Scott. I am the Regional Manager of Dunder Mifflin Paper Products. Just wanted to talk to you manager-a-manger. [quick cut scene] All right. Done deal. Thank you very much, sir. You’re a gentleman and a scholar. Oh, I’m sorry. OK. I’m sorry. My mistake. [hangs up] That was a woman I was talking to, so… She had a very low voice. Probably a smoker, so… [Clears throat] So that’s the way it’s done."
), Season = c(1, 1, 1, 1, 1, 1), Episode_Number = c(1, 1, 1, 
1, 1, 1)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", 
"data.frame"))

编辑 2: 之前我说过 df$col <- gsub("\'","", df$col) 在 R studio 工作。这只适用于玩具数据。我在 dput 上使用它但没有用,所以我回到原点。

您输入的是“花哨引号”,而不是标准引号。这应该摆脱所有花哨的单引号和双引号以及所有非花哨的单引号:

gsub("['‘’”“]", "", df$Line)