Unexpected behavior using -which() in R when the search term is not found

前端 未结 3 1249
南旧
南旧 2021-01-21 05:18

I have been using the R which function to remove rows from a data frame. I recently discovered that if the search term is NOT in the data.frame, the result is an e

3条回答
  •  执笔经年
    2021-01-21 05:42

    In example 2, which returns integer(0) (a zero-length integer vector) because no values are TRUE. A negative zero-length vector (-integer(0)) is still a zero-length vector. So you're essentially asking for the NULL element of LETTERS, which doesn't exist.

提交回复
热议问题