Replace single quote with double quote in a column in R

筅森魡賤 提交于 2019-12-04 07:08:33

问题


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.


回答1:


Try this:

"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)



来源:https://stackoverflow.com/questions/44298123/replace-single-quote-with-double-quote-in-a-column-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!