Skip to content

Header = T

5 messages · lucky7, Richard M. Heiberger, Peter Dalgaard +1 more

#
Hi,

I just start to use R today! I am reading the R Help on read.csv and the
description for header says "header is set to TRUE if and only if the first
row contains one fewer field than the number of columns". Why is that? My
data has the same number of fields in the first row as the number of
columns. I mean I have no problem opening my csv file I am just curious why
it should be one fewer.

Thanks!

--
View this message in context: http://r.789695.n4.nabble.com/Header-T-tp4097045p4097045.html
Sent from the R help mailing list archive at Nabble.com.
#
On 11/23/2011 06:47 AM, lucky7 wrote:
Hi lucky7,
This looks like one of those little obscurities that sometimes appear in 
the help files. The default for read.csv is header=TRUE and I guess that 
the "...header is set to TRUE..." part means that if your file has one 
less field in the first line, header will be forced to TRUE as this is a 
part of the CSV specification. As Douglas Adams might have said,

"Don't panic."

Jim
#
On Nov 23, 2011, at 10:03 , Jim Lemon wrote:

            
Actually, no. It's a "little obscurity" alright, but the root cause is that the help file was originally written for read.table, with read.csv and friends as later bolt-ons. These actually call read.table internally, but if the header argument is missing to read.csv, the default (TRUE) will be passed to read.table. Thus, there is no way to induce the first-line-shorter logic. No big deal; nobody writes CSV files following that convention anyway. 

The situation is in turn a niggle in the R language itself: missingness does not propagate.

  
    
#
On 11/23/2011 09:38 PM, peter dalgaard wrote:
Hmmm, my guess was wrong, but to quote Monty Python, "I do", or at least 
I struggled mightily with this leading delimiter business in the 
"delim.table" function. I do appreciate the expert correction, though.