You can use readLines()
with strsplit()
:
test <- strsplit(readLines("MyFile.csv"),",")
Question
I have a csv file with a few million lines. Each line can have lengths between 5 and 10. I can use read.table()
to read in the data by padding out each row to length 10 with NAs or empty strings, however, removing these NAs later is time consuming. I would like to read the file into a list of vectors, so that each line can have it's own list element, negating the need for padding the rows with NAs or empty strings.
La solution
You can use readLines()
with strsplit()
:
test <- strsplit(readLines("MyFile.csv"),",")