From d@vidhughjone@ @ending from gm@il@com  Sat Aug  4 15:55:34 2018
From: d@vidhughjone@ @ending from gm@il@com (David Hugh-Jones)
Date: Sat, 4 Aug 2018 14:55:34 +0100
Subject: [Rd] Puzzle or bug with matrix indexing
Message-ID: <CAARY7kgosh2XgT+DDg9Y7CQwERdwTrn7AO1MAvV-tS0e=_O0SA@mail.gmail.com>

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"

Notice there is a space before the TRUE: " TRUE".

This space isn't happening purely because of coercion:

c("blah", TRUE, FALSE)
[1] "blah"  "TRUE"  "FALSE"

No space.

Obviously:
as.logical(tmp[idx])
[1]    NA FALSE

which is why I think this might be a bug.

David

	[[alternative HTML version deleted]]



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