Warning message:number of items to replace is not a multiple of replacement length
Posted Data+Science+Insight
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Warning message:number of items to replace is not a multiple of replacement length相关的知识,希望对你有一定的参考价值。
Warning message:In df$a[is.na(df$a)] <- df$b :number of items to replace is not a multiple of replacement length
目录
问题:
#想用第二列的对应值填充第一列的缺失值;
#如下方法缺失值的个数和第二列数值的个数不对等,那么就会造成没有使用对应的位置进行填充,而是使用第二列的从上到下的值依次填充,没有达到对应填充的目的;
# 正确的方式应当是使用ifelse
#create data frame
df <- data.frame(a=c(3, NA, 7, NA, NA, 14),
b=c(4, 4, 5, 12, 13, 18))
#view data frame
df
df$a[is.na(df$a)] <- df$b
df
a b
1 3 4
2 4 4
3 7 5
4 4 12
5 5 13
6 14 18
解决:
#create data frame
df <- data.frame(a=c(3, NA, 7, NA, NA, 14),
b=c(4, 4, 5, 12, 13, 18))
#view data frame
df
df$a <- ifelse(is.na(df$a), df$b, df$a)
df
完整错误:
> df$a[is.na(df$a)] <- df$b
Warning message:
In df$a[is.na(df$a)] <- df$b :
number of items to replace is not a multiple of replacement length
> df
a b
1 3 4
2 4 4
3 7 5
4 4 12
5 5 13
6 14 18
以上是关于Warning message:number of items to replace is not a multiple of replacement length的主要内容,如果未能解决你的问题,请参考以下文章
Warning: RPMDB altered outside of yum
WARNING: The TCP backlog setting of 511.解决
用keil编译提示 warning: #...: last line of file ends without a newline
warning: implicit declaration of function ‘basename’ [-Wimplicit-function-declaration]
warning: implicit declaration of function ‘sleep’(添加头文件: #include <unistd.h>)