If I index the data.frame of all matrix integers, I get the expected result.
df <- data.frame(c1=1:4, c2=5:8) df1 # c1 c2 #1 1 5 #2 2 6 #3 3 7 #4 4 8 df1[matrix(c(1:4,1,2,1,2), nrow=4)] # [1] 1 6 3 8
If there is a character column in data.frame, the result will be all characters, although I only index entire columns.
df2 <- data.frame(c0=letters[1:4], c1=1:4, c2=5:8) df2 # c0 c1 c2 #1 a 1 5 #2 b 2 6 #3 c 3 7 #4 d 4 8 df2[matrix(c(1:4,2,3,2,3), nrow=4)] # [1] "1" "6" "3" "8" class(df[matrix(c(1:4,2,3,2,3), nrow=4)]) # [1] "character" df2[1,2] # [1] 1
My best guess: R is too busy to go through the answer to check if they all came from a particular class. Can someone explain why this is happening?
source share