[R] read in csv.-data file with blanks and missing values

David McPearson dmcp at webmail.co.za
Mon Jan 18 10:14:50 CET 2016


swizz-john wrote:

> Hi people,
> 
> my task is to analyse data that is formatted like this.
> 
>
date,bid,name,w1,w2,w3,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,debt2mkt,cds,equity
> 28jul2009,1,"ABN Amro",,,,,,,,,,,,,,,,,56.5,
> 29jul2009,1,"ABN Amro",,,,,,,,,,,,,,,,,56.5,
> 30jul2009,1,"ABN Amro",,,,,,,,,,,,,,,,,55,
> 31jul2009,1,"ABN Amro",,,,,,,,,,,,,,,,,55,
> 03aug2009,1,"ABN
Amro",.35,.4,.45,,.71,.96,1.05,1.14,1.22,1.26,1.3,1.35,1.38,1.41,1.44,,55,
> 06aug2009,1,"ABN
Amro",.35,.4,.45,,.72,.92,1,1.1,1.18,1.2,1.23,1.28,1.32,1.35,1.38,,53.75,

##
## Er - no, it'snot.
##

> 
> It has 21 columns but not every column has a value, some only have commas
instead.
> 
> My file is named: test_data.csv and it is attached here:
> test_data.csv

If I open your attachment with Excel I see what you have above. If I open it
with LibreOffice Calc I see the same as you are getting in R.

When I open test_dta.csv with a plain text editor (I used Tinn-R, Notepad
should also work) I see why you are not getting wjat you expect. Take a
careful look at the data: All the commas are contained withing matching pairs
of quotation marks. Hence they are all treated as plain text by sensible
software.

Hope this helps,
Dave.

PS - If this comes through as html can someone flame me, please. I'm using a
web based service and don't yet know what format it sends...
Thanks.

____________________________________________________________
South Africas premier free email service - www.webmail.co.za



More information about the R-help mailing list