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

前端 未结 3 1250
南旧
南旧 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

    Because of this:

    which(LETTERS == '-1')
    ## integer(0)
    

    and this:

    (1:2)[integer(0)]
    integer(0)
    

    Instead of #4, use this:

    LETTERS[LETTERS != "R"]
    

提交回复
热议问题