使用命令时出现报错:
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"
标签:tmp,sep,NA,header,报错,factor,count3
From: https://www.cnblogs.com/chenwenyan/p/17045775.html