从R中的data.frame中删除引号(“”)

时间:2021-08-31 18:55:28

I have a data.frame with several columns, all of them are character class. All values are in double quotes, I would like to remove those quotes.

我有一个包含多个列的data.frame,它们都是字符类。所有值都是双引号,我想删除这些引号。

Example

df1      df2
"1203"   "Name1"
"2304"   "Name2"

1 个解决方案

#1


14  

The print() method for data frames has an option quote=, which you can set to FALSE:

数据框的print()方法有一个选项quote =,您可以将其设置为FALSE:

print.data.frame(data.frame(x=c("Hello", "World")), 
                 quote=FALSE)
#       x
# 1 Hello
# 2 World

See also ?print.data.frame(= help)

另见?print.data.frame(= help)

Edit:

编辑:

With regards to the dputed data in the comment below:

关于以下评论中的dputed数据:

as.data.frame(sapply(df, function(x) gsub("\"", "", x)))

#1


14  

The print() method for data frames has an option quote=, which you can set to FALSE:

数据框的print()方法有一个选项quote =,您可以将其设置为FALSE:

print.data.frame(data.frame(x=c("Hello", "World")), 
                 quote=FALSE)
#       x
# 1 Hello
# 2 World

See also ?print.data.frame(= help)

另见?print.data.frame(= help)

Edit:

编辑:

With regards to the dputed data in the comment below:

关于以下评论中的dputed数据:

as.data.frame(sapply(df, function(x) gsub("\"", "", x)))