嗨,我有一个数据框
status Value
OFF 22
ON 34
OFF NA
ON NA
OFF 22
ON 12
ON NA
当我的条件匹配时,我试图用之前的非NA值替换NA值,即IF NA找到状态为' ON'如果状态为ON,则替换为先前的非NA
df$required= ifelse(df$status='ON'& is.na(df$value),
na.locf(df$value,na.rm=F),df$value)
错误:意外','在"
status Value required
OFF 22 22
ON 34 34
OFF NA NA
ON NA 34
OFF 22 22
ON 12 12
ON NA 12
任何修改都会被评估,谢谢