[R] Reading one column .csv file

peter dalgaard pdalgd at gmail.com
Wed Aug 15 22:46:10 CEST 2012


On Aug 15, 2012, at 22:11 , John Kane wrote:

> I cannot duplicate this using LibreOffice Calc.  It saves exactly as one would expect.
> 

I can duplicate it with Excel on OSX. Each line of the CSV file ends with a comma!

Corresponding thing happens if you save as .txt (TAB-delimited) and read with read.delim().

However, select all followed by read.delim from the clipboard works fine. Go figure...

You can skip the empty column using

read.csv("~/Downloads/cyu01_iqscores.csv",colClasses=list("numeric",NULL))

but deleting the extra column is just as expedient.


> John Kane
> Kingston ON Canada
> 
> 
>> -----Original Message-----
>> From: dwarnold45 at suddenlink.net
>> Sent: Wed, 15 Aug 2012 10:27:54 -0700 (PDT)
>> To: r-help at r-project.org
>> Subject: [R] Reading one column .csv file
>> 
>> My friend sent an Excel file:
>> 
>> http://msemac.redwoods.edu/~darnold/temp/cyu01_iqscores.xls
>> http://msemac.redwoods.edu/~darnold/temp/cyu01_iqscores.xls
>> 
>> I opened it in Excel, saved is as cyu01_iqscores.csv, then imported it
>> into
>> R with:
>> 
>> iqscores=read.csv('cyu01_iqscores.csv',header=TRUE)
>> 
>> The result was:
>> 
>>> head(iqscores)
>>  IQ.Scores  X
>> 1       145 NA
>> 2       101 NA
>> 3       123 NA
>> 4       106 NA
>> 5       117 NA
>> 6       102 NA
>> 
>> Now, I know I can cure this with:
>> 
>> iqscores=iqscores[,1]
>> 
>> But I am wondering about this weird behavior.
>> 
>> Suggestions?
>> 
>> David
>> 
>> 
>> 
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Reading-one-column-csv-file-tp4640396.html
>> Sent from the R help mailing list archive at Nabble.com.
>> 
>> ______________________________________________
>> R-help at r-project.org 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.
> 
> ____________________________________________________________
> FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
> 
> ______________________________________________
> R-help at r-project.org 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list