Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何替换<;NA>;特定列的值?_R_Factors - Fatal编程技术网

R 如何替换<;NA>;特定列的值?

R 如何替换<;NA>;特定列的值?,r,factors,R,Factors,我想将行为空的列中的值替换为我的列tech.role的“NO” mental.health$tech.role <- as.factor(mental.health$tech.role) levels(mental.health$tech.role)<-c("No","Yes") Error in `levels<-.factor`(`*tmp*`, value = c("No", "Yes")) : number of levels differs mental.he

我想将行为空的列中的值替换为我的列tech.role的“NO”

mental.health$tech.role <- as.factor(mental.health$tech.role)
levels(mental.health$tech.role)<-c("No","Yes")
Error in `levels<-.factor`(`*tmp*`, value = c("No", "Yes")) : 
  number of levels differs

mental.health$tech.role
mental.health$tech.role[is.na(mental.health$tech.role)]请使用
dput
功能将
mental.health
数据框添加到问题中(强调最小值)。这将帮助我们找出问题所在,并为您提供有用的答案
mental.health$tech.role[is.na(mental.health$tech.role)] <- 'NO'