xin wei
2011-Mar-02 04:52 UTC
[R] a question on sqldf's handling of missing value and factor
Dear subscribers: I am using the following code to read a large number of big text files: library(sqldf) tempd <- file(XXXX) tempdx <- sqldf("select * from tempd", dbname = tempfile(), file.format list(header = T, sep="\t", row.names = F)) The problem is: all my numberical variable become factor (maybe because these columns all contain missing value). It would be quite cubersome to convert them to numeric variable using as.numeric one by one. Does anyone know how to re-set SQLDF so that it would automatically read the numeric column with missing row as real numeric instead of factor? many thanks -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-sqldf-s-handling-of-missing-value-and-factor-tp3331007p3331007.html Sent from the R help mailing list archive at Nabble.com.
Gabor Grothendieck
2011-Mar-02 13:02 UTC
[R] a question on sqldf's handling of missing value and factor
On Tue, Mar 1, 2011 at 11:52 PM, xin wei <xinwei at stat.psu.edu> wrote:> Dear subscribers: > > I am using the following code to read a large number of big text files: > library(sqldf) > tempd <- file(XXXX) > tempdx <- sqldf("select * from tempd", dbname = tempfile(), file.format > list(header = T, sep="\t", row.names = F)) > > The problem is: all my numberical variable become factor (maybe because > these columns all contain missing value). It would be quite cubersome to > convert them to numeric variable using as.numeric one by one. Does anyone > know how to re-set SQLDF so that it would automatically read the numeric > column with missing row as real numeric instead of factor? >If you can provide a minimal ***reproducible*** example it would help. Maybe sqldf(..., method = "raw") will give you what you want but I can't say for sure without the example. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com