Folkes, Michael
2011-Apr-04 22:05 UTC
[R] RODBC excel - need to preserve (or extract) numeric column names
I'm using RODBC to read an excel file (not mine!). But I'm struggling to find a way to preserve the column names that have a numeric value. sqlFetch() drops the value and calls them f1, f2, f3,... (ie field number). this is a different approach from read.csv, which will append "V" prior to the numeric column name. sqlFetch isn't so helpful. Is there a way to get the first line of data from the excel file and place it in a vector? Perhaps I can use that method and rename the dataframe column names later? thanks! Michael _______________________________________________________ Michael Folkes Salmon Stock Assessment Canadian Dept. of Fisheries & Oceans Pacific Biological Station 3190 Hammond Bay Rd. Nanaimo, B.C., Canada V9T-6N7 Ph (250) 756-7264 Fax (250) 756-7053 Michael.Folkes@dfo-mpo.gc.ca <mailto:Michael.Folkes@dfo-mpo.gc.ca> [[alternative HTML version deleted]]
David Winsemius
2011-Apr-04 22:33 UTC
[R] RODBC excel - need to preserve (or extract) numeric column names
On Apr 4, 2011, at 6:05 PM, Folkes, Michael wrote:> I'm using RODBC to read an excel file (not mine!). But I'm > struggling to find a way to preserve the column names that have a > numeric value. sqlFetch() drops the value and calls them f1, f2, > f3,... (ie field number). this is a different approach from > read.csv, which will append "V" prior to the numeric column name.read.table() (and perhaps read.csv) has a check.names argument which defaults to TRUE but can be set to FALSE. You will then need to take special care with the result, since those are not "safe" column names. Another way would be to read only one line in with readLines and then assign to names(dfrm) which would be read in with `skip` = 1.> sqlFetch isn't so helpful. > > Is there a way to get the first line of data from the excel file and > place it in a vector? Perhaps I can use that method and rename the > dataframe column names later? > > thanks! > Michael-- David Winsemius, MD West Hartford, CT
Enrico Schumann
2011-Apr-05 08:53 UTC
[R] RODBC excel - need to preserve (or extract) numeric column names
At least for Excel 2003 on my computer (Win XP) I can "persuade" Excel to treat cells like text by prepending a ' to the entry (eg, '1000). Then sqlFetch/RODBC should import these cells as character. [But a number would not be valid column name for a data.frame, and you may run into other trouble. See ?make.names] regards, enrico> -----Urspr?ngliche Nachricht----- > Von: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] Im Auftrag von Folkes, Michael > Gesendet: Dienstag, 5. April 2011 00:05 > An: r-help at r-project.org > Betreff: [R] RODBC excel - need to preserve (or extract) > numeric column names > > I'm using RODBC to read an excel file (not mine!). But I'm > struggling to find a way to preserve the column names that > have a numeric value. sqlFetch() drops the value and calls > them f1, f2, f3,... (ie field number). this is a different > approach from read.csv, which will append "V" prior to the > numeric column name. sqlFetch isn't so helpful. > > Is there a way to get the first line of data from the excel > file and place it in a vector? Perhaps I can use that method > and rename the dataframe column names later? > > thanks! > Michael > > _______________________________________________________ > Michael Folkes > Salmon Stock Assessment > Canadian Dept. of Fisheries & Oceans > Pacific Biological Station > 3190 Hammond Bay Rd. > Nanaimo, B.C., Canada > V9T-6N7 > Ph (250) 756-7264 Fax (250) 756-7053 > Michael.Folkes at dfo-mpo.gc.ca <mailto:Michael.Folkes at dfo-mpo.gc.ca> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.