[Rd] Puzzle or bug with matrix indexing

David Hugh-Jones d@vidhughjone@ @ending from gm@il@com
Sat Aug 4 15:55:34 CEST 2018


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]]



More information about the R-devel mailing list