Friday 15 January 2010

r - fread does not drop whitespace before column names? -


Then I am using the fread function to read a .csv file. Some headers have empty spaces in them, such as headers B, C and E:

headerA, headerb, headerc, headerd, headerE

I use A selected fread function can only be read in the headerb and headerC . After that, referred to any header gives me this problem:

& gt;

with Foo [, "headerb", = FALSE] and if I add a position in front of the header name, then it works:

& Gt; Foo [, with "headerB", = FALSE] (shows the data correctly)

which means that the name of the header as part of fread Parsing the front spot makes it difficult to use the syntax after this type of colernames string like foo $ headerB , etc.

Anyway, to get this problem, setname (foo, "head b", "header b") on abusive columns?

The actual fread command was used: foo & lt; - fread ("data.csv", ColClasses = list (NULL = c (1: 5,8: 14), "POSIXct" = c (5,6))) . I left sep as originally automatically , but sep = "" did not help .

Thank you.

data.table allows you to name unchecked columns, and Due to this, it is not really known when your places are deliberately and when they are mistaken.

Since you know yourself what should not be there, you can easily fix it:

  set name (foo, sub ('^ *') , '', Name (af))  

No comments:

Post a Comment