我有一个如下的数据帧,我想动态地将DEPT_Head = "DEV0001"
赋给我的脚本
df <- data.frame(HOD_ID =c("","KTN2252","ANA2719","ITI2624","DEV2698","HRT2921","","KTN2624","ANA2548","ITI2535","DEV2732","HRT2837","ERV2951","KTN2542","ANA2813","ITI2210"),
DEPT_Head = c("DEV0001","KTN2252","ANA2719","ITI2624","DEV2698","HRT2921","ERV0000","KTN2624","ANA2548","ITI2535","DEV2732","HRT2837","ERV2951","KTN2542","ANA2813","ITI2210"))
我的代码总是需要输入参数DEPT_Head = "DEV0001"
现在,如果用户输入Dept_head
的HOD_ID
应该为空,并且如果除了用户输入参数之外还有其他空白单元格,则我想将新列更改为1对于用户定义的DEPT_Head
,HOD_I
D应该始终为空,否则如果有任何空白细胞,则将if_blank
突变为1
对于用户作为输入参数提供的HOD_ID
,第一个检查Dept_head
应该为空。第二个是除了用户输入的dept_head
id之外,不应该有任何空的单元格,如果发现任何空单元格,则将新列突变为1
您可以尝试:
DEPT_Head = "DEV0001"
df$if_blank <- as.integer(df$DEPT_Head != DEPT_Head & df$HOD_ID == '')