Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
> x1=c(4,5,6,7,8) > x1 [1] 4 5 6 7 8 > x2=x1[x1!=6] > x2 [1] 4 5 7 8 > x3=x1[x1=6] > x3 [1] NA
为什么x3不是6?我不明白。
x3
=是赋值运算符。通过使用x1[x1=6],您正在分配6to的值,而x1不是检查它们是否匹配。在?assignOpsR 提示符下输入以获取更多信息。改为使用==。
=
x1[x1=6]
6
x1
?assignOps
==
x3=x1[x1==6]