How is TRUE interpreted when used as matrix index?

前端 未结 2 782
野趣味
野趣味 2021-01-21 01:43

I saw some (bad) code somewhere which turned out to call a function which executed mymatrix[TRUE] along the way. It turns out, at least in the samples I tested, t

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-21 01:54

    When used as indices, logical vectors are recycled to match the length of the vector. For example, mymatrix[c(TRUE, FALSE)] would give you every other element.

提交回复
热议问题