Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我是 R 新手,我想做一些简单的事情。我缺少 R 作为 NA 的值,我用平均值替换了它们。替换这些值后,我想创建一个新变量。这是我试图获取新变量的内容:
mydata$xyz[is.na(mydata$xyz)] <- mean(mydata$xyz, na.rm = TRUE) = mydata$xyz2
感谢帮助!
尝试
mydata$xyz2 <- mydata$xyz mydata$xyz2[is.na(mydata$xyz)] <- mean(mydata$xyz, na.rm = TRUE)