Using col_names in read_excel

85 views
Skip to first unread message

Bob

unread,
Jun 23, 2015, 10:29:45 AM6/23/15
to manip...@googlegroups.com
Hi All,

I'm just passing along a useful tip about specifying column names in an Excel file. I was using the readxl package's read_excel function to read a spreadsheet that already had column names in the top row. I needed to rename the variables so I thought using the col_names option would be a dandy way to do that. Bad idea! If you specify col_names, then you're telling read_excel that the file does not already have them. So when read_excel is guessing the type of each variable, it sees the unexpected variable names and assumes all the variables must be text. How I noticed this was my date column came out as "42011.412719907406" instead of "2015-01-07 09:54:19 UTC". At first, I went blindly on to specify the col_types argument to fix the date until it finally hit me that providing names was also essentially setting col_names = FALSE. 

Cheers,
Bob
Reply all
Reply to author
Forward
0 new messages