数据:
DB <- data.frame(orderItemID = 1:10,
color= c("black",NA,"red","green",NA, "blue","red","black",NA,"black"))
预期结果:
DB <- data.frame(orderItemID = 1:10,
color= c("black","black","red","green","black","blue","red","black","black","black"))
下午好!
这次我需要用数据集中最常用的颜色(在示例中为黑色)替换NA条目。因为在我的原始数据集中不清楚最常用的颜色是否有必要首先找出最常用的颜色,然后重新输入到数据集。
尝试过这样,但它没有用(第一行似乎是正确的,但第二行是错的):
most_freqcolor <- names(which.max(table(DB$color)))
DB[is.na(DB$color)] <- most_freqcolor
希望你们有一些想法可以轻松解决它:)