[R] Expanding a data structure

William Dunlap wdunlap at tibco.com
Mon Mar 1 17:30:38 CET 2010


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Worik R
> Sent: Sunday, February 28, 2010 9:37 PM
> To: r-help
> Subject: Re: [R] Expanding a data structure
> 
> >   change <- c(NA, diff(q1$..1))
> > will be 1 when ..1 goes from FALSE
> > to TRUE, -1 for TRUE to FALSE, 0 for no change, and NA
> > for the first element.  You may find it convenient to
> > change that NA to something else or to not deal with
> > the first element after computing the diff.
> >
> >
> This is very helpful, I did not know about the notation V$..1
> 
> I can find no documentation for it, but it works.

There are lots of ways to refer to the column
of a rectangular dataset.

I took the name "..1" from the printed column
name in your dataset
   I have a xts object with logical data .
   
   > tail(q1)
                ..1
   2010-02-19  TRUE
   2010-02-22 FALSE
   2010-02-23 FALSE
   2010-02-24 FALSE
   2010-02-25 FALSE
   2010-02-26 FALSE
For data.frame and, I assume, xts objects the syntax
   object$columnName
refers to the column of the dataset with that name.
You can also use
   object[["columnName"]]
If you don't know the name you can use
   object[[1]]
to mean the first column.

You can also use matrix notation (2 subscripts)
for selecting a column from a data.frame:
   object[,1]
or
   object[,"columnName"]

Note that object[2] or object["columnName"] return
data.frames containing the desired column, not the
column itself.


> 
> cheers
> Worik
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 



More information about the R-help mailing list