[R] when to use textConnection ??

Gabor Grothendieck ggrothendieck at gmail.com
Tue Aug 17 02:33:10 CEST 2010


On Mon, Aug 16, 2010 at 8:07 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Mon, Aug 16, 2010 at 8:00 PM, skan <juanpide at gmail.com> wrote:
>>
>> I've just seen that sep sep cannot be ","  because there are not commas in
>> the file.
>> but I want it to take the first and second columns (date and time) as a
>> whole, the index.
>>
>
> In the latest version of zoo index.column= can be a list.
> index.column = list(1:2), which can be abbreviated to just
> index.column = 1:2, would pass the first two columns to FUN as a
> single argument consisting of a two column matrix whereas index.column

That should read a two column data.frame.

> = list(1, 2) would pass them as separate arguments.  Using the latter:
>
> Lines <- "date           time        value
> 1999-11-11 10:20:00  1.2222"
>
> library(zoo)
> library(chron)
>
> # z <- read.zoo("myfile.dat", index = list(1, 2),  header = TRUE,
>
> z <- read.zoo(textConnection(Lines), index = list(1, 2),  header = TRUE,
>        FUN = function(date, time) as.chron(paste(date, time)))
>



More information about the R-help mailing list