问答详情
源自:4-4 注意事项

求教:write.csv中的参数qmethod = c("escape", "double")是什么意思?

求教大家:qmethod = c("escape", "double")是什么意思? write.csv(x, file = "", append = FALSE, quote = TRUE, sep = " ",             eol = "\n", na = "NA", dec = ".", row.names = TRUE,             col.names = TRUE, qmethod = c("escape", "double"),             fileEncoding = "")

提问者:神州晨曦 2017-07-18 17:08

个回答

  • 慕斯4041028
    2018-01-07 20:57:46

    qmethod其实就是quote method的意思

    举例如下:

    > e='escape quote method(缺省) 将字符型数据中的引号"替换为反斜杠+引号';e
    [1] "escape quote method(缺省) 将字符型数据中的引号\"替换为反斜杠+引号"
    > d='double quote method 将字符型数据中的引号"替换为两个引号';d
    [1] "double quote method 将字符型数据中的引号\"替换为两个引号"
    > write.table(e,"escape-qmethod.txt",row.names=F)
    > write.table(d,"double-qmethod.txt",qmethod="d",row.names=F)

    打开"escape-qmethod.txt"和"double-qmethod.txt"看到:

    escape-qmethod.txt:

    "x"
    "escape quote method(缺省) 将字符型数据中的引号\"替换为反斜杠+引号"

    double-qmethod.txt:

    "x"
    "double quote method 将字符型数据中的引号""替换为两个引号"

    注意:如果用单引号括起字符,就不需要给双引号加反斜杠转义符。