Re: [Rd] mydataframe$colname: using substring of colname may also match some column (PR#7496)

From: Tony Plate <tplate_at_acm.org>
Date: Thu 13 Jan 2005 - 03:57:44 EST

At Wednesday 03:50 AM 1/12/2005, marc@intershop.de wrote:
>Full_Name: Marc Mamin
>Version: 1.8, 2.0.0
>OS: Windows & Linux
>Submission from: (NULL) (217.17.202.254)
>
>[snipped issues previously responded to]
>
>Here another example that underline how problematic this issue can be:
>
>aa1<-1
>aa2<-2
>df<-as.data.frame(aa1,aa2)
> > df$aa
>[1] 1 (only the first matching column is retrieved)

Actually, the above commands constructed a data frame with one column (the second argument to 'as.data.frame' is 'row.names'):

 > aa1<-1
 > aa2<-2
 > df <- as.data.frame(aa1,aa2)
 > df

   aa1
2 1
 > dim(df)
[1] 1 1

When a data frame (or list) does have columns whose names have common prefixes, the behavior is as documented (NULL is returned):

 > df2 <- data.frame(aa1, aa2)
 > df2
   aa1 aa2
1 1 2
 > df2$aa
NULL
 >



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Jan 13 03:03:44 2005

This archive was generated by hypermail 2.1.8 : Thu 13 Jan 2005 - 03:21:02 EST