I have a series of string marked by quotation marks and I'd like them to be separated by comma so that I can pass them to a vector. I tried paste command but I kept getting error messages. Thank you. The data is like:
"Alabama" "Arkansas" "Connecticut" "Georgia" "Hawaii" "Minnesota" "Mississippi" "Missouri" "Oregon"
答案 0 :(得分:0)
您可以尝试以下内容:
str <- '"Alabama" "Arkansas" "Connecticut" "Georgia" "Hawaii" "Minnesota"
"Mississippi" "Missouri" "Oregon"'
gsub('\\"',"",gsub('\\"\\s+\\"',",",str))
#[1] "Alabama,Arkansas,Connecticut,Georgia,Hawaii,Minnesota,Mississippi,Missouri,Oregon"
<强>正则表达式:强>
\\"\\s+\\"
- 在"
中查找多个空格并替换为","