[R] Error in reading subset of data from CSV file

Christofer Bogaso bogaso.christofer at gmail.com
Sun Sep 4 09:54:33 CEST 2016


Hi again,

I was trying to read a subset of Data from a CSV file using below code
as example :

library(sqldf)

Dat = structure(list(`col 1` = c(133261L, 133261L, 133262L, 133262L
), `col 2` = structure(1:4, .Label = c("aaa1", "aaa2", "bbb1, bbb",
"bbb3, bbb"), class = "factor"), `col 3` = c(10.59, 10.56, 10.59,
10.56), `col 4` = c(10.59, 10.56, 10.59, 10.56), `col 5` = c(10.59,
10.56, 10.59, 10.56), `col 6` = structure(c(1L, 2L, 1L, 2L), .Label =
c("04-Jul-16",
"05-Jul-16"), class = "factor")), .Names = c("col 1", "col 2",
"col 3", "col 4", "col 5", "col 6"), class = "data.frame", row.names = c(NA,
-4L))
Dat

write.csv(Dat, "Dat.csv", quote = FALSE, row.names = FALSE)

ReadName = '133261'
read.csv.sql("Dat.csv", sql = "select * from file where 'col 1' = ReadName")

Loading required package: tcltk
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  line 1 did not have 7 elements

This code generates above Error. Could you please help me with a
pointer where something went wrong? My actual CSV file is quite huge
so I cant read it as whole. However basic structure of my original
file is similar as above "Dat"

Thanks for your time.



More information about the R-help mailing list