import csv file into R, strange problem

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

import csv file into R, strange problem

bonnieyuan
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?
Reply | Threaded
Open this post in threaded view
|

Re: import csv file into R, strange problem

Greg Snow-2
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.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of bonnieyuan
Sent: Tuesday, September 13, 2011 10:09 AM
To: [hidden email]
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?

--
View this message in context: http://r.789695.n4.nabble.com/import-csv-file-into-R-strange-problem-tp3810470p3810470.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: import csv file into R, strange problem

David Winsemius

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: [hidden email] [mailto:[hidden email]
> ] On Behalf Of bonnieyuan
> Sent: Tuesday, September 13, 2011 10:09 AM
> To: [hidden email]
> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: import csv file into R, strange problem

Rainer M Krug-6
In reply to this post by bonnieyuan
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 13/09/11 18:08, bonnieyuan wrote:
> 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?

Maybe Microsoft? We had the problem in South Adfrica, that if the
locale was set to South African English, then the csv was ";"
seperated - don't tell me why.

So: check your csv if it is really a csv.

Cheers,

Rainer


>
> -- View this message in context:
> http://r.789695.n4.nabble.com/import-csv-file-into-R-strange-problem-tp3810470p3810470.html
>
>
Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________ [hidden email]
> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
> read the posting guide http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.


- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      [hidden email]

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5wZZEACgkQoYgNqgF2egqGfgCeKWohnNQONvSge1M6Bf9OtBMP
ln4An1n64fYAwNfTzc3rbD/tRXx9ksry
=XYvm
-----END PGP SIGNATURE-----

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: import csv file into R, strange problem

Uwe Ligges-3


On 14.09.2011 10:28, Rainer M Krug wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 13/09/11 18:08, bonnieyuan wrote:
>> 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?
>
> Maybe Microsoft? We had the problem in South Adfrica, that if the
> locale was set to South African English, then the csv was ";"
> seperated - don't tell me why.

Probably MS expects that South Africans, like Germans, use a comma ","
as the decimal "point", and hence the separator is ";". That's why
read.csv2() is available - reading that pseudo comma separated format..

Uwe Ligges


>
> So: check your csv if it is really a csv.
>
> Cheers,
>
> Rainer
>
>
>>
>> -- View this message in context:
>> http://r.789695.n4.nabble.com/import-csv-file-into-R-strange-problem-tp3810470p3810470.html
>>
>>
> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________ [hidden email]
>> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
>> read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
> - --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
>
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax :       +33 - (0)9 58 10 27 44
>
> Fax (D):    +49 - (0)3 21 21 25 22 44
>
> email:      [hidden email]
>
> Skype:      RMkrug
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk5wZZEACgkQoYgNqgF2egqGfgCeKWohnNQONvSge1M6Bf9OtBMP
> ln4An1n64fYAwNfTzc3rbD/tRXx9ksry
> =XYvm
> -----END PGP SIGNATURE-----
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: import csv file into R, strange problem

Rainer M Krug-6
On Wed 14 Sep 2011 10:37:46 CEST, Uwe Ligges wrote:

>
>
> On 14.09.2011 10:28, Rainer M Krug wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> On 13/09/11 18:08, bonnieyuan wrote:
>>> 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?
>>
>> Maybe Microsoft? We had the problem in South Adfrica, that if the
>> locale was set to South African English, then the csv was ";"
>> seperated - don't tell me why.
>
> Probably MS expects that South Africans, like Germans, use a comma ","
> as the decimal "point", and hence the separator is ";". That's why
> read.csv2() is available - reading that pseudo comma separated format..

Good to know - I should have known that at that time - it caused me
several headaches.

Rainer

>
> Uwe Ligges
>
>
>>
>> So: check your csv if it is really a csv.
>>
>> Cheers,
>>
>> Rainer
>>
>>
>>>
>>> -- View this message in context:
>>> http://r.789695.n4.nabble.com/import-csv-file-into-R-strange-problem-tp3810470p3810470.html
>>>
>>>
>>>
>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________ [hidden email]
>>> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
>>> read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>> - --
>> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>> Biology, UCT), Dipl. Phys. (Germany)
>>
>> Centre of Excellence for Invasion Biology
>> Stellenbosch University
>> South Africa
>>
>> Tel :       +33 - (0)9 53 10 27 44
>> Cell:       +33 - (0)6 85 62 59 98
>> Fax :       +33 - (0)9 58 10 27 44
>>
>> Fax (D):    +49 - (0)3 21 21 25 22 44
>>
>> email:      [hidden email]
>>
>> Skype:      RMkrug
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.11 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>
>> iEYEARECAAYFAk5wZZEACgkQoYgNqgF2egqGfgCeKWohnNQONvSge1M6Bf9OtBMP
>> ln4An1n64fYAwNfTzc3rbD/tRXx9ksry
>> =XYvm
>> -----END PGP SIGNATURE-----
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: import csv file into R, strange problem

bonnieyuan
Thanks for all the input. You were right. It was not csv file in the  
correct format. As it turned out, it's not a R problem, more a MAC  
problem. For some reason, my MAC doesn't correctly download csv file  
from internet, which caused all the subsequent problems. I will have  
to take it to a mac shop.

Quoting Rainer M Krug <[hidden email]>:

> On Wed 14 Sep 2011 10:37:46 CEST, Uwe Ligges wrote:
>>
>>
>> On 14.09.2011 10:28, Rainer M Krug wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> On 13/09/11 18:08, bonnieyuan wrote:
>>>> 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?
>>>
>>> Maybe Microsoft? We had the problem in South Adfrica, that if the
>>> locale was set to South African English, then the csv was ";"
>>> seperated - don't tell me why.
>>
>> Probably MS expects that South Africans, like Germans, use a comma ","
>> as the decimal "point", and hence the separator is ";". That's why
>> read.csv2() is available - reading that pseudo comma separated format..
>
> Good to know - I should have known that at that time - it caused me
> several headaches.
>
> Rainer
>>
>> Uwe Ligges
>>
>>
>>>
>>> So: check your csv if it is really a csv.
>>>
>>> Cheers,
>>>
>>> Rainer
>>>
>>>
>>>>
>>>> -- View this message in context:
>>>> http://r.789695.n4.nabble.com/import-csv-file-into-R-strange-problem-tp3810470p3810470.html
>>>>
>>>>
>>>>
>>> Sent from the R help mailing list archive at Nabble.com.
>>>>
>>>> ______________________________________________ [hidden email]
>>>> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
>>>> read the posting guide http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>> - --
>>> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>>> Biology, UCT), Dipl. Phys. (Germany)
>>>
>>> Centre of Excellence for Invasion Biology
>>> Stellenbosch University
>>> South Africa
>>>
>>> Tel :       +33 - (0)9 53 10 27 44
>>> Cell:       +33 - (0)6 85 62 59 98
>>> Fax :       +33 - (0)9 58 10 27 44
>>>
>>> Fax (D):    +49 - (0)3 21 21 25 22 44
>>>
>>> email:      [hidden email]
>>>
>>> Skype:      RMkrug
>>> -----BEGIN PGP SIGNATURE-----
>>> Version: GnuPG v1.4.11 (GNU/Linux)
>>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>>
>>> iEYEARECAAYFAk5wZZEACgkQoYgNqgF2egqGfgCeKWohnNQONvSge1M6Bf9OtBMP
>>> ln4An1n64fYAwNfTzc3rbD/tRXx9ksry
>>> =XYvm
>>> -----END PGP SIGNATURE-----
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.