I try to import a txt/csv file with R, and here is a simplified example:
txt <- "
id,value
001,'Mary'
002,'Mary's, husband'"
For the second line, I would like to consider the value of the variable value
as Mary's, husband
delimited with '
and there is also '
after Mary
.
We can use ignore the quotes and clean after importing. But since ,
is also the separator, there is a bug when importing as follows:
df1 <- read.csv(textConnection(txt))
df1$value <- gsub("^'|'$", "", df1$value)
df1
My question is how to import the data correctly in this case, to have Mary's, husband
as a single value.
[Update]: as one comment points out, this file is not correctly buit. But we can consider that there are always two columns, and the first ,
is the separator for one row.