[R] Specifying data type when creating a dataframe using RODBC

Mark Na mtb954 at gmail.com
Tue May 12 23:59:30 CEST 2009

H R-helpers,

I am using the following code to make a dataframe from an Excel spreadsheet:

channel <- odbcConnectExcel("Spreadsheet.xls")
Data <- sqlFetch(channel, "Tab1")

One column (several, actually) in the spreadsheet contains integers in
its first few rows but later values in these columns contain a mixture
of numbers, letters and symbols (it's an ID variable, containing e.g.,
12, 14, 19, 19B, 19C, 19/20)

R creates this column as a numeric variable (I think because its first
few variables are numbers) but as soon as R gets to the non-numeric
values (e.g., 19/20) it replaces them with NA.

So, my question is: how can I specify that certain columns are to be
read as character variables BEFORE the dataframe is created?

I have tried using as.character() in the third line (above) but it
creates a very long first column containing all of my data...

Thanks for any help you might provide,

Mark Na

More information about the R-help mailing list