> 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
Why is x3
not 6? I don't understand.
<-
and =
are assignment operators. By using x1[x1=6]
, you are assigning the value of 6
to x1
, not checking whether they match. Type in ?assignOps
at the R prompt for more info. Use ==
instead.
x3 <- x1[x1==6]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With