为什么元素向量比较返回FALSE?

时间:2017-04-01 13:37:06

标签: r

也许这有点多余,但仍然困扰着我。为什么我需要将矢量转换为integer class以使元素比较正确?

# Finding a linear combination of v, in terms of u1,u2,u3
v=c(3,7,-4)

u1=c(1,2,3)
u2=c(2,3,7)
u3=c(3,5,6)

# L. System AX=B
A <- cbind(u1,u2,u3)
B <- v
k <- solve(A,B)
k
## Therefore
u <- k[1]*u1+k[2]*u2+k[3]*u3

# First elemement FALSE?
v==u
identical(v,u)
all(v==u)
v %in% u

#Both numeric
is.numeric(v)==is.numeric(u)
u <- as.integer(u)

# The elemnt-wise comparison is now correct, identical FALSE, because they are a different class.
v==u
identical(v,u)
all(v==u)
v %in% u

0 个答案:

没有答案