Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen using read.csv, why is entire row converted to <NA> is first value in row is <NA>
    primarykey
    data
    text
    <p>I've using the following <code>read.csv</code> command to read in a csv data file containing only 1,540 rows of data. For some reason if the first field in a row is empty then the entire row is returned as NA as shown below. </p> <pre><code>data = read.csv(full_path, header = TRUE, sep = ",", strip.white = TRUE, fill = TRUE, na.strings = c('NA','','NULL','#N/A'), row.names = NULL, blank.lines.skip = TRUE) </code></pre> <p>The file contains 5 useful fields followed by 365 fields which I remove. A sample of the file is shown below:</p> <pre><code>id,conm,No Data,Ticker,Cusip,,,,,,,,,,, 001010-01,ACF INDUSTRIES HOLDING CORP,TRUE,,00099V004^,,,,,,,,,,, 001040-01,AMF INC,TRUE,AMF,001688100^,,,,,,,,,,, . . 002444-01,BRUNSWICK CORP,TRUE,BC,117043109^,,,,,,,,,,, ,BURLINGTON INDUSTRIES INC,TRUE,121693972,121693972^,,,,,,,,,,, 002490-01,BURLINGTON NORTHERN INC.,TRUE,BNI,12189T104^,,,,,,,,,,, </code></pre> <p>So in the above CSV sample the data for company 'BURLINGTON INDUSTRIES INC' is lost as the id is empty.</p> <pre><code> id conm ticker cusip 2 001010-01 ACF INDUSTRIES HOLDING CORP &lt;NA&gt; 00099V004 3 001040-01 AMF INC AMF 001688100 4 001045-01 AMR CORP/DE AAMRQ 001765106 . . 80 002444-01 BRUNSWICK CORP BC 117043109 NA &lt;NA&gt; &lt;NA&gt; &lt;NA&gt; &lt;NA&gt; 82 002490-01 BURLINGTON NORTHERN INC. BNI 12189T104 </code></pre> <p>I haven't found this behaviour documented, but is this supposed to happen? There are other fields which are empty but this behaviour doesn't occur. I first tried it without <code>'row.names = NULL'</code> and <code>'blank.lines.skip = TRUE'</code> and has the same effect.</p> <p>If I remove the trailing 365 fields from the file, then the read works as expected. I have checked the number of fields trailing the rows and each one contains the same number.</p> <p>Thanks for your help.</p> <p>** UPDATE **</p> <p>I made a mistake, the error wasn't in the read.csv but in the line of code following it as outlined in the answer below.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload