I am trying to load a comma-delimited data file that also has commas in one of its text columns. The following sample code generates such a file'test.csv',
which I'll load usingread.csv()
to illustrate my problem.
> d <- data.frame(name = c("John Smith", "Smith, John"), age = c(34, 34))
> d
name age
1 John Smith 34
2 Smith, John 34
> write.csv(d, file = "test.csv", quote = F, row.names = F)
> d2 <- read.csv("test.csv")
> d2
name age
John Smith 34 NA
Smith John 34
Because of the ','
in Smith, John
, d2
is not assigned correctly. How do I read the file so that d2
looks exactly like d
?
Thanks.