如何用行均值估算缺失值?

How do I impute missing values with row mean?

我想使用行均值来估算 VPS8 的缺失值。

综合考虑意见,编辑如下:

VPS8 <- data.frame(YAL002W=as.numeric(cdc15["YAL002W",]))
ind <- which(is.na(VPS8), arr.ind=TRUE)
VPS8[ind] <- rowMeans(VPS8, na.rm=TRUE)[ind[,1]]

返回值为:

num[1:6] NaN NaN NaN NaN NaN NaN

期望的输出 用行平均值估算缺失值并另存为。

对于错误,请尝试将 VPS8 转换为数据帧。 编辑:

VPS8 <- data.frame(YAL002W=as.numeric(cdc15["YAL002W",]))
time <- as.numeric(row.names.data.frame(VPS8))
df <- data.frame(VPS8,time)
ind <- which(is.na(df), arr.ind=TRUE)
df[ind] <- rowMeans(df, na.rm=TRUE)[ind[,1]]

检查这是否有效