I have a series of numbers that include both whole numbers and decimals. When I try to subset this list using a series of numbers, it ignores the decimals while subsetting. How do I get the subset range to include decimals?
Note: I understand that seq
can be used to create a sequence with different decimals (e.g., see here), but what if I want to do so using actual values from my data instead of a newly created sequence?
Is this possible?
For example:
vec <- c(-1, 0, 0.5, 0.9, 1, 1.2, 1.3, 5, 5.4, 6, 7, 9)
vec[!(vec %in% 0:2)]
[1] -1.0 0.5 0.9 1.2 1.3 5.0 5.4 6.0 7.0 9.0
#But what I want is:
[1] -1.0 5.0 5.4 6.0 7.0 9.0
And
vec[!(vec %in% 1.2:5.4)]
[1] -1.0 0.0 0.5 0.9 1.0 1.3 5.0 5.4 6.0 7.0 9.0
#But what I want is:
[1] -1.0 0.0 0.5 0.9 1.0 6.0 7.0 9.0