Reputation: 25
I need to filter a numeric variable by the value of its decimals i.e. Selecting 19.00 and not 19.53. I only want to select numbers with a decimal value of .00. Is there any way to do this?
Upvotes: 2
Views: 660
Reputation: 389205
You could get the decimal part, compare and subset
x <- c(19.00, 19.53, 18.000, 13.98)
x[x %% 1 == 0]
#[1] 19 18
where
x %% 1 #returns
#[1] 0.00 0.53 0.00 0.98
Upvotes: 3