[R] Selecting the "non-attribute" part of an object

Bert Gunter gunter.berton at gene.com
Thu Nov 15 21:59:03 CET 2012


max(abs(x-y))  < numerical tolerance of your choice

-- Bert

On Thu, Nov 15, 2012 at 11:52 AM, Jonathan Dushoff <dushoff at mcmaster.ca> wrote:
> I have two matrices, generated by R functions that I don't understand.
>  I want to confirm that they're the same, but I know that they have
> different attributes.
>
> If I want to compare the dimnames, I can say
>
>> identical(attr(tm, "dimnames"), attr(tmm, "dimnames"))
> [1] FALSE
>
> or even:
>
>> identical(dimnames(tm), dimnames(tmm))
> [1] FALSE
>
> But I can't find any good way to compare the "main" part of objects.
>
> What I'm doing now is:
>
>> tm_new <- tm
>> tmm_new <- tmm
>
>> attributes(tm_new) <- attributes(tmm_new) <- NULL
>
>> identical(tm_new, tmm_new)
> [1] TRUE
>
> But that seems very inaesthetic, besides requiring that I create two
> pointless objects.
>
> I have read ?attributes, ?attr and some web introductions to how R
> objects work, but have not found an answer.
>
> Thanks for any help.
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm




More information about the R-help mailing list