实施例
test <- unlist(strsplit(noquote(string), ","))
test <- gsub("[^A-Za-z0-9' ']", "", test)
gsub("^\\s+|\\s+$", "", test)
[1] "field1" "field2" "there is a" "in field3"
[5] "field4" "2" "456" "field6"
否定尝试:
\" ... \"
请注意,包含逗号的字段位于{{1}}。
之间答案 0 :(得分:2)
read.table函数将忽略引号内的逗号。
string <- "field1,field2,\"there is a , in field3\", field4, \"2,456\", field6"
desired_result <- read.table(text=string, sep=",")