[R] Reading a specific column of a csv file in a loop
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Nov 15 16:10:21 CET 2011
On Tue, Nov 15, 2011 at 9:44 AM, Juliet Hannah <juliet.hannah at gmail.com> wrote:
> In the solution below, what is the advantage of using "0L".
>
> M0 <- read.csv("M1.csv", nrows = 1)[0L, ]
>
As mentioned, you will find quite a bit of additional info on the
sqldf home page but to address the specific question regarding the use
of 0L in this code:
library(sqldf)
library(RH2)
M0 <- read.csv("M1.csv", nrows = 1)[0L, ]
M1.subset.h2 <- sqldf(c("insert into M0 (select * from csvread('M1.csv'))",
"select a, d, g, h from M0"))
in order to use H2's csvread function we must first create the table
into which csvread reads as csvread does not itself create tables. It
only fills in existing tables. In SQL the table creation is done with
a create statement
create table M0(a real, b real, ...etc.)
This creates a table with zero rows; however, with 2000 columns that
would be an enormous create statement as every one of the 2000 columns
would have to be listed; therefore, we just upload a zero row table,
M0, from R instead.
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list