Warning message:In a + b : longer object length is not a multiple of shorter object length
目录
Warning message:In a + b : longer object length is not a multiple of shorter object length
问题:
想对两个向量进行按位相加,不过b向量的长度比a向量小一位,以至于我们如下看到的例子中的最后一个数值:11= 5+6
#即位数不够的时候倒回来从第一个开始补起来。
#define two vectors
a <- c(1, 2, 3, 4, 5)
b <- c(6, 7, 8, 9)
#add the two vectors
a + b
********************************************************************************
[1] 7 9 11 13 11
Warning message:
In a + b : longer object length is not a multiple of shorter object length
解决:
如果长度不对等则在b向量的尾部补零处理;
#define two vectors
a <- c(1, 2, 3, 4, 5)
b <- c(6, 7)
#add zeros to the end of vector b
for(i in ((length(b)+1):length(a)))
+{b = c(b, 0)}
#add the two vectors
a + b
[1] 7 9 11 13 5
完整错误:
> #add the two vectors
> a + b
[1] 7 9 11 13 11
Warning message:
In a + b : longer object length is not a multiple of shorter object length
>