R语言:In `[<-.factor`(`*tmp*`, thisvar, value = " ") : invalid factor level, NA generated报错
使用命令时出现报错:
count3 = read.table("summary.txt",header=T,sep="\t")
count3[is.na(count3)] <- "rs111"
In `[<-.factor`(`*tmp*`, thisvar, value = "rs111") :
invalid factor level, NA generated
报错原因
"rs111"是character,而我要替换的NA属性为factor,factor属性的NA不能替换为character属性的"rs111"
解决办法
加上stringsAsFactors = FALSE
参数:
count3 = read.table("summary.txt",header=T,sep="\t", stringsAsFactors = FALSE)
count3[is.na(count3)] <- "rs111"
本文来自博客园,作者:橙子牛奶糖(陈文燕),转载请注明原文链接:https://www.cnblogs.com/chenwenyan/p/17045775.html