[R] adding logical vector to data frame

Prof Brian D Ripley ripley at stats.ox.ac.uk
Fri Sep 7 21:57:06 CEST 2001


R version?

This works correctly in R-devel.  Yes, using $ on data frame subverts some
of the conversions, but logical variables are full-status variables now.


On 7 Sep 2001, Thomas Vogels wrote:

>
> Hello.  I'm afraid that I'm missing something very obvious this
> afternoon...
>
> When I add a column to a data.frame (by assigning to a "new" column
> name a logical vector), I thought that I had (at least) 3 options to
> do so:
>
> R> j <- data.frame (x=1:2)
>
> R> j$y <- c(TRUE,FALSE) #assignment 1
> R> str(j)
> `data.frame':	2 obs. of  2 variables:
>  $ x: int  1 2
>  $ y: logi   TRUE FALSE
>
> R> j[["y"]] <- c(TRUE,FALSE) #assignment 2
> R> str(j)
> `data.frame':	2 obs. of  2 variables:
>  $ x: int  1 2
>  $ y: Factor w/ 2 levels "FALSE","TRUE": 2 1
>
> R> j[["y"]] <- I(c(TRUE,FALSE)) #assignment 3
> R> str(j)
> `data.frame':	2 obs. of  2 variables:
>  $ x: int  1 2
>  $ y:Class 'AsIs'  logi [1:2]  TRUE FALSE
>
>
> Why is assignment 1 not identical to either assignment 2 or 3?  Is
> there a method dispatch skipped?
>
> Thanks!
>   -tom
>
>
> --
> mailto:tov at ece.cmu.edu (Tom Vogels)   Tel: (412) 268-6638   FAX: -3204
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list