From d@vidhughjone@ @ending from gm@il@com  Sat Aug  4 21:47:17 2018
From: d@vidhughjone@ @ending from gm@il@com (David Hugh-Jones)
Date: Sat, 4 Aug 2018 20:47:17 +0100
Subject: [Rd] Puzzle or bug with matrix indexing
In-Reply-To: <C1C93F6E-FDD1-4687-BC45-4671C90B548F@ucsd.edu>
References: <CAARY7kgosh2XgT+DDg9Y7CQwERdwTrn7AO1MAvV-tS0e=_O0SA@mail.gmail.com>
 <C1C93F6E-FDD1-4687-BC45-4671C90B548F@ucsd.edu>
Message-ID: <CAARY7kimfojC=_UCnMczyOTHDMaFXyOoHKFSoPpWr4xWGdMJpg@mail.gmail.com>

Yup, I worked it out in time... for future reference, as.matrix calls
`format` on logicals, converting them to the form seen.

On Sat, 4 Aug 2018 at 17:53, Berry, Charles <ccberry at ucsd.edu> wrote:

>
>
> > On Aug 4, 2018, at 6:55 AM, David Hugh-Jones <davidhughjones at gmail.com>
> wrote:
> >
> > I'm not sure why this is happening:
> >
> > tmp <- data.frame(
> >  a = letters[1:2],
> >  b=c(TRUE, FALSE),
> >  stringsAsFactors = FALSE
> > )
> > idx <- matrix(c(1, 2, 2, 2), 2, byrow = TRUE)
> > tmp[idx]
> >
> > [1] " TRUE" "FALSE"
> >
>
> From ?"[.data.frame"
>
> Extract.data.frame {base}
> .
> .
> .
> Matrix indexing (x[i] with a logical or a 2-column integer matrix i) using
> [ is not recommended. For extraction, x is first coerced to a matrix.
>
> [...]
>
> Thus, something like
>
>         as.matrix(tmp)
>
> happens converting every column to character. Dig deeper by reading
>
> ?matrix
>
> and see the paragraph on `as.matrix' under `Details'.
>
> HTH,
>
> Chuck
>
-- 
Sent from Gmail Mobile

	[[alternative HTML version deleted]]



[Rd] Puzzle or bug with matrix indexing
David Hugh-Jones