【发布时间】:2018-04-18 08:05:18
【问题描述】:
我的数据在 write.csv in R 之后得到了这个结果:
Last_Name,Sales,Country,Quarter
Smith,$16,753.00 ,UK,Qtr 3
Johnson,$14,808.00 ,USA,Qtr 4
Williams,$10,644.00 ,UK,Qtr 2
我想要这个结果(这是我数据的原始格式):
Last_Name,Sales,Country,Quarter
Smith,"$16,753.00 ",UK,Qtr 3
Johnson,"$14,808.00 ",USA,Qtr 4
Williams,"$10,644.00 ",UK,Qtr 2
因为显然我在金额上有些问题!
但我不想:
"Last_Name","Sales","Country","Quarter"
"Smith,"$16,753.00 ","UK","Qtr 3"
"Johnson","$14,808.00 ","USA","Qtr 4"
"Williams","$10,644.00 ","UK","Qtr 2"
有什么想法吗?
【问题讨论】:
-
销售栏的类型是什么?
-
尝试使用
df1$Sales <- shQuote(df1$Sales),然后使用quote = FALSE写入csv -
销售列是字符串,我无法更改格式
-
df1$Sales <- shQuote(df1$Sales)不起作用,因为它添加了单引号,我需要双引号。