dimanche 24 décembre 2017

'which' function in R returns row = 1 while the matched value is in row 2?

I have a translation table where I am using do.call(paste, input) %in% do.call(paste, big_translation_table).

It returns TRUE or FALSE.

Then I am using which function to find the index, but it always returns 1.

Please advise.

Here is a small example:

test1 <- data.frame(a = 1, b=2, c = "r", stringsAsFactors = FALSE)
test2 <- data.frame(a = c(1,2), b=c(2,10), c = c("r","p"), stringsAsFactors = FALSE)

which(do.call(paste, test1) %in% do.call(paste, test2))

returns 1 and it's ok, now let's test with:

test1 <- data.frame(a = 2, b=10, c = "p", stringsAsFactors = FALSE)
which(do.call(paste, test1) %in% do.call(paste, test2))

returns 1 too. I think it should return 2.

Please advise.

Aucun commentaire:

Enregistrer un commentaire