barnhillec
barnhillec

Reputation: 356

R read.csv with comma delimiter and character newline

I would like R to read.csv with comma delimiter but semicolon newline. The data has no white space or newlines. How can I do this?

Upvotes: 1

Views: 3376

Answers (1)

Feng Mai
Feng Mai

Reputation: 3109

One solution is reading the file as a string and replacing semicolon by new line symbol.

fileName = 'myfile.txt'
filecontent = readChar(fileName, file.info(fileName)$size)
filecontent = gsub(";", "\n", filecontent)
con = textConnection(filecontent)
read.table(con,sep=",")

Upvotes: 5

Related Questions