I am trying to do something like this:
data %>%
filter(col1 == 1.03e-06)
Is there a way to reference e-06 without having to type out the entire number?
I am trying to do something like this:
data %>%
filter(col1 == 1.03e-06)
Is there a way to reference e-06 without having to type out the entire number?
I think you've already got it (provided the number is exactly that):
library(tidyverse)
df <- data.frame(col1 = c(1.03e-06, 0.00000103))
df %>%
filter(col1 == 1.03e-06) #should return both rows
You need to be careful when dealing with floating point numbers though, so you should use a function like all.equal()
In such cases.
Thank you for your response. How would it look like if I do have floating point numbers? For example:
data %>%
filter(which(round(col1) == 7.728055e-06))
==
with floats.You may fall into the floating point trap.
Also, calling round
on your column is going to give you a vector of integers. Those shouldn't ever be ==
to 7.7e-6
near
@martin.R meant you should use the near
function when comparing floating point numbers using dplyr
df %>% filter(near(col1, 7.72e-06))
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.