在R的列中用双引号替换单引号 [英] Replace single quote with double quote in a column in R

查看:120
本文介绍了在R的列中用双引号替换单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在R中的数据框有一个A列,其中有带单引号的字符串数据。

My dataframe in R has a column A where I have string data with single quote in it.

Column A
'Hello World'
'Hi World'
'Good morning world'

我想做的是用双引号替换单引号并实现如下所示的输出。

What I would like to do is to replace the single quote with double quotes and achieve the output like below.

Column A
"Hello World"
"Hi World"
"Good morning world

这可以实现吗?
预先感谢您阅读。

Can this be achieved? Thank you in advance for reading.

推荐答案

尝试一下:

iris是一个示例数据框,我试图替换 Species列的单引号。由于'和是字符串中的特殊字符,因此使用转义序列指定它们:

"iris" is a sample data frame and I am trying to replace single quotes of "Species" column. Since ' and " are special characters within strings hence they are specified using escape sequences:

iris $ Species<-gsub( \', \,iris $ Species)

这篇关于在R的列中用双引号替换单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆