[R] adding logical vector to data frame

Thomas Vogels tov at ece.cmu.edu
Fri Sep 7 21:31:45 CEST 2001


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list