[R] import csv file into R, strange problem

David Winsemius dwinsemius at comcast.net
Tue Sep 13 22:34:31 CEST 2011


On Sep 13, 2011, at 12:58 PM, Greg Snow wrote:

> It would appear that your file is not a csv file, but we cannot tell  
> for sure without seeing an example of the data that you are reading  
> in, can you cut and paste the first few lines of the file? Or post a  
> link to a copy of the file.  If the data is not able to be shared,  
> then create a new (small) file with made up data that displays the  
> same problems (creating the example sometimes helps you fix the  
> problem yourself) then share that file.
>
> Also why are you specifying sep="," in read.csv? that is a bit  
> redundant.

Indeed. I'm surprised it doesn't throw an error. Usually trying to set  
an argument twice (even if it is the same value)  would create an  
error.  Further evidence that this was not the actual code is provided  
by the space in the "file name". I have seen Excel files that were  
missing commas to actually be tab-separated files, so this might work.

read.table(file.name, header=T, sep="\t")

>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org 
> ] On Behalf Of bonnieyuan
> Sent: Tuesday, September 13, 2011 10:09 AM
> To: r-help at r-project.org
> Subject: [R] import csv file into R, strange problem
>
> Hi, I used read.csv(file name, header=T, sep=",") to bring in a csv  
> file I
> saved in MS Excel. The strange thing is all the data ended up in one  
> big
> column. The number of rows match with the number of observations,  
> but all
> the variables got squeezed into one column. Also the first row where  
> the
> header is, the variables names have a dot between them, replacing  
> the comma
> that's in the original csv file.
>
> What did I do wrong here?



David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list