When trying to replace values, “missing values are not allowed in subscripted assignments of data frames”

前端 未结 6 1517
日久生厌
日久生厌 2021-02-01 14:31

I have a table that has two columns: whether you were sick (H01) and the number of days sick (H03). However, the number of days sick is NA if H01 == false, and I would like to s

6条回答
  •  野的像风
    2021-02-01 14:59

    I realise the question is very old, but I think the most elegant solution is by using the which() function:

     pe94.person[which(pe94.person$H01 == 12),]$H03 <- 0
    

    should do what the original poster asked for. Because which() drops the NAs and keeps the (positions of the) TRUE results only.

提交回复
热议问题