本文介绍了找到并替换行平均值的缺失值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个NAs的数据框,我想用行代替NAs c1 = c(1, 2,3,NA) c2 = c(3,1,NA,3) c3 = c(2,1,3,1) df = data。框架(c1,c2,c3) > df c1 c2 c3 1 1 3 2 2 2 1 1 3 3 NA 3 4 NA 3 1 ,以便 > df c1 c2 c3 1 1 3 2 2 2 1 1 3 3 3 3 4 2 3 1 解决方案非常类似于@ baptiste的答案 > ind > df [ind]< - rowMeans(df,na.rm = TRUE)[ind [,1]] I have a data frame with NAs and I want to replace the NAs with row meansc1 = c(1,2,3,NA)c2 = c(3,1,NA,3)c3 = c(2,1,3,1)df = data.frame(c1,c2,c3)> df c1 c2 c31 1 3 22 2 1 13 3 NA 34 NA 3 1so that > df c1 c2 c31 1 3 22 2 1 13 3 3 34 2 3 1 解决方案 Very similar to @baptiste's answer> ind <- which(is.na(df), arr.ind=TRUE)> df[ind] <- rowMeans(df, na.rm = TRUE)[ind[,1]] 这篇关于找到并替换行平均值的缺失值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 13:59