my dataset looks like
df <- data.frame( ID= c(1,1,2,2,3,3,4,4),
TIME = c(0,10,0,20,0,25,0,44),
DV = C(0.25,0.25,5,5,6,6,7,7))
i want to make DV as NA whenever TIME is 0
my dataset looks like
df <- data.frame( ID= c(1,1,2,2,3,3,4,4),
TIME = c(0,10,0,20,0,25,0,44),
DV = C(0.25,0.25,5,5,6,6,7,7))
i want to make DV as NA whenever TIME is 0
suppressPackageStartupMessages({library(dplyr)})
# avoid built-in identifier df
dat <- data.frame( ID= c(1,1,2,2,3,3,4,4),
TIME = c(0,10,0,20,0,25,0,44),
DV = c(0.25,0.25,5,5,6,6,7,7)) # not C
dat %>% mutate(DV = ifelse(TIME == 0,NA,TIME))
#> ID TIME DV
#> 1 1 0 NA
#> 2 1 10 10
#> 3 2 0 NA
#> 4 2 20 20
#> 5 3 0 NA
#> 6 3 25 25
#> 7 4 0 NA
#> 8 4 44 44
Created on 2020-09-16 by the reprex package (v0.3.0)
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.