Skip to content
Prev 41348 / 63421 Next

read.csv behaviour

On 09/28/2011 09:23 AM, Mehmet Suzen wrote:
Hi Mehmet,
The example doesn't need to call "file", writeLines does it for you. It 
worked for me:

  writeLines(c("A,B,C,D",
               "1,a,b,c",
               "2,f,g,c",
               "3,a,i,j",
               "4,a,b,c",
               "5,d,e,f",
               "6,g,h,i,j,k,l,m,n"),
             con="test.csv")

and to get the original object back, use:

readLines("test.csv")

The reason you can't use read.csv is that it returns a data frame, and 
that object can't have elements of unequal length. If you want an object 
with elements of unequal length, try:

as.list(readLines("test.csv"))

Jim