Comments (2)
This is a typical problem with floating point numbers. Manually typing in 7.0001
and generating the supposedly equivalent value with seq()
results in two different numbers under the hood:
options(digits = 22)
seq(0,10, 0.0001)[70002]
#> [1] 7.00010000000000065512
7.0001
#> [1] 7.000099999999999766942
They are close, but not quite the same. There is a nice python article about this:
https://docs.python.org/3/tutorial/floatingpoint.html
In general, filtering or joining on fractional numbers like this is going to be problematic. For filtering, one solution is to use near()
:
library(dplyr)
longseq <- data.frame(time = seq(0,10, 0.0001))
longseq[70002,]
#> [1] 7.0001
longseq %>% filter(near(time, 7.0001))
#> time
#> 1 7.0001
For joins, you should try to avoid using floating point numbers if you can, or at least round them to the nearest second first if they are times. If you really need fractional seconds, you could look into nanotime or clock, which have "true" subsecond types that aren't backed by floating point types, so they would work better for that.
Other than that, there isn't much dplyr can do here
from dplyr.
Thank you Davis Vaughan!
this helped me a lot. And thank you for the very fast reply and pointing to the other two packages. I will have a look on using different classes for joining data frames.
from dplyr.
Related Issues (20)
- Native pipe does not work with rowwise HOT 6
- Release dplyr 1.1.4 HOT 1
- Emphasize that filter(x, A, B) is not strictly the same as filter(filter(x, A), B) HOT 4
- Spurious warnings about many-to-many joins HOT 5
- Feature request: allow additional predicates in join_by HOT 2
- Feature Request: In across, have function for `.names` argument HOT 2
- Feature request/Question: do not drop extra classes (and attributes) with functions group_by, summarise and so HOT 1
- relocate: naming index-identified column triggers warning unless index wrapped in all_of() et al. HOT 6
- Unexpected behavior with rename/rename_with HOT 3
- Code don't work in version 1.1.4 HOT 1
- A better data masking indirection example in the `programming.Rmd` vignette: `filter(df, {{ var }})`
- Not correctly escaping column names in sql for `duckdb` connection HOT 1
- arrange not reporting syntax errors on .by_group HOT 1
- Unable to pass n to dplyr::slice
- Feature Request: profiling options for a chain of pipes HOT 1
- `cur_column()` not working in `case_when()` LHS HOT 1
- perfromance slowdown using across within mutate HOT 1
- Update `.groups` message after `group_by() |> summarize()`
- Request: Add a .by argument to slice_ functions to match main verbs HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dplyr.