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

前端 未结 6 1565
日久生厌
日久生厌 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:56

    Following works. Watch out there is no comma in sub setting:

    x <- data.frame(a=c(NA,2:5), b=c(1:5))
    
    x$a[x$a==2] <- 99
    

提交回复
热议问题