From b.rowlingson at lancaster.ac.uk  Tue Jun  2 19:23:00 2009
From: b.rowlingson at lancaster.ac.uk (Barry Rowlingson)
Date: Tue, 2 Jun 2009 18:23:00 +0100
Subject: [Rd] setdiff bizarre (was: odd behavior out of setdiff)
In-Reply-To: <8b356f880906020813w6b7075b6g411fc177b508709e@mail.gmail.com>
References: <a695148b0905292135g1c1bee38xb70687a43ccaa934@mail.gmail.com>
	<8b356f880905300550y39c76b02h2d908b1c6b0ef0e4@mail.gmail.com>
	<a695148b0905300721x6e291e0bg66fefcf0931f2ce2@mail.gmail.com>
	<8b356f880905300859i5ba5800q5594bfce659373fe@mail.gmail.com>
	<8b356f880906020813w6b7075b6g411fc177b508709e@mail.gmail.com>
Message-ID: <d8ad40b50906021023u406a77bfke070c8b925385723@mail.gmail.com>

On Tue, Jun 2, 2009 at 4:13 PM, Stavros Macrakis <macrakis at alum.mit.edu> wrote:

> but simply treats the data frame as a *character* list:
>
> ? ? 1 %in% data.frame(a=2,b=1) ?# TRUE
> ? ? '1' %in% data.frame(a=2,b=1) ?# TRUE
> ? ? 1 %in% data.frame(a=2:3,b=1:2) # FALSE
> ? ? 1:3 %in% data.frame(a=2:4,b=1:3) ?# FALSE FALSE FALSE
> ? ? '1:3' %in% data.frame(a=2:4,b=1:3) ?# TRUE

It applies as.character to the dataframe:

 > z=data.frame(a=2:4,b=1:3)
 > as.character(z)
 [1] "2:4" "1:3"

  The as.character method for data frames seems to spot integer
sequences (but only for int types and not num types) and show the a:b
notation:

 > x=data.frame(z=as.integer(c(1,2,3,4,5)))
 > str(x)
 'data.frame':	5 obs. of  1 variable:
  $ z: int  1 2 3 4 5
 > as.character(x)
 [1] "1:5"

 Obviously it doesn't do this for vectors:

 > as.character(x$z)
 [1] "1" "2" "3" "4" "5"

 I suspect it's using 'deparse()' to get the character representation.
This function is mentioned in ?as.character, but as.character.default
disappears into the infernal .Internal and I don't have time to chase
source code - it's sunny outside!

Barry



[Rd] setdiff bizarre (was: odd behavior out of setdiff)
Barry Rowlingson