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

Tony Plate tplate at acm.org
Wed Jan 12 17:57:44 CET 2005


At Wednesday 03:50 AM 1/12/2005, marc at 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
 >



More information about the R-devel mailing list