[R] How do I add a variable to a text file?

Duncan Murdoch murdoch at stats.uwo.ca
Fri Mar 20 00:46:31 CET 2009


On 19/03/2009 4:55 PM, Guillaume Filteau wrote:
> Hello all,
> 
> I have a 2.0 GB dataset that I can't load into R, due to memory issues. 
> The dataset itself is in a tab-delimited .txt file with 25 variables.
> 
> I have a variable I'd like to add to the dataset. How do I do this? Best,

Read a block, add the variable, write the block, and repeat?  For 
example, the reading part is done with

con <- file("somename.txt", "r")
block1 <- read.table(con, nrows=blocksize)

block2 <- read.table(con, nrows=blocksize, head=FALSE, 
col.names=names(block1))

...

close(con)

The writing part is similar, but depends a lot on the details of what 
you're doing.

Duncan Murdoch




More information about the R-help mailing list