An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100519/494aeb24/attachment.pl>
Strange case of partial matching in .[ - possible bug / wrong documentation?
4 messages · Duncan Murdoch, David Winsemius, Hilmar Berger
On 19/05/2010 12:14 PM, Hilmar Berger wrote:
Hi all, This occurred in R-2.11.0 (WinXP). The R-help page of .[ says that: "Character indices can in some circumstances be partially matched (see pmatch) to the names or dimnames of the object being subsetted (but never for subassignment). Unlike S (Becker et al p. 358)), R has never used partial matching when extracting by [, and as from R 2.7.0 partial matching is not by default used by [[ (see argument exact)." My understanding is therefore that .[ should never try partial matching.
See near the top of the page: "The descriptions here apply only to the default methods." Since indexing is generic, an extraction method can do whatever it wants, and you need to read the particular page to find the behaviour. The page for Extract.data.frame says: "Both |[| and |[[| extraction methods partially match row names. By default neither partially match column names, but |[[| will unless |exact=TRUE|. If you want to do exact matching on row names use |match <http://127.0.0.1:28754/library/base/help/match>| as in the examples." Duncan Murdoch
However:
df = data.frame(a=c(1,2,3,9), b=c(4,5,6,10))
rownames(df) = c("ef","gg","hh","fe")
df
a b ef 1 4 gg 2 5 hh 3 6 fe 9 10
df["e",]
a b ef 1 4
rownames(df) = c("ef","gg","hh","efg")
df["e",]
a b
NA NA NA
So, it looks like partial matching is done using pmatch("e",rownames(df))
for "[". If this is true, the help page is not correct.
Thanks !
Regards,
Hilmar
---
Hilmar Berger
Integromics S.L. / CNB-CSIC
Madrid, Spain
[[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.
On May 19, 2010, at 12:14 PM, Hilmar Berger wrote:
Hi all, This occurred in R-2.11.0 (WinXP). The R-help page of .[ says that: "Character indices can in some circumstances be partially matched (see pmatch) to the names or dimnames of the object being subsetted (but never for subassignment). Unlike S (Becker et al p. 358)), R has never used partial matching when extracting by [, and as from R 2.7.0 partial matching is not by default used by [[ (see argument exact)." My understanding is therefore that .[ should never try partial matching.
That was for [.matrix or similar (as noted at top of the page). You created a different class of variable. ?"[.data.frame "Both [ and [[ extraction methods partially match row names. By default neither partially match column names, but [[ will unless exact=TRUE. If you want to do exact matching on row names use match as in the examples."
David.
>
> However:
>
>> df = data.frame(a=c(1,2,3,9), b=c(4,5,6,10))
>> rownames(df) = c("ef","gg","hh","fe")
>> df
> a b
> ef 1 4
> gg 2 5
> hh 3 6
> fe 9 10
>
>
>> df["e",]
> a b
> ef 1 4
>
>> rownames(df) = c("ef","gg","hh","efg")
>> df["e",]
> a b
> NA NA NA
>
> So, it looks like partial matching is done using
> pmatch("e",rownames(df))
> for "[". If this is true, the help page is not correct.
>
> Thanks !
> Regards,
> Hilmar
>
> ---
> Hilmar Berger
> Integromics S.L. / CNB-CSIC
> Madrid, Spain
>
> [[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.
David Winsemius, MD
West Hartford, CT
Duncan Murdoch schrieb:
On 19/05/2010 12:14 PM, Hilmar Berger wrote:
Hi all, This occurred in R-2.11.0 (WinXP). The R-help page of .[ says that: "Character indices can in some circumstances be partially matched (see pmatch) to the names or dimnames of the object being subsetted (but never for subassignment). Unlike S (Becker et al p. 358)), R has never used partial matching when extracting by [, and as from R 2.7.0 partial matching is not by default used by [[ (see argument exact)." My understanding is therefore that .[ should never try partial matching.
See near the top of the page: "The descriptions here apply only to the default methods." Since indexing is generic, an extraction method can do whatever it wants, and you need to read the particular page to find the behaviour. The page for Extract.data.frame says: "Both |[| and |[[| extraction methods partially match row names. By default neither partially match column names, but |[[| will unless |exact=TRUE|. If you want to do exact matching on row names use |match <http://127.0.0.1:28754/library/base/help/match>| as in the examples." Duncan Murdoch
Sorry, I should have read the complete help page. Thanks a lot ! Best regards, Hilmar