I would use which.min
which.min(abs(x-0.4))
This will return the first index of the closest number to 0.4
.
More Related Contents:
- Collapse / concatenate / aggregate a column to a single comma separated string within each group
- Select / assign to data.table when variable names are stored in a character vector
- Replace all 0 values to NA
- How to convert a list consisting of vector of different lengths to a usable data frame in R?
- How to open CSV file in R when R says “no such file or directory”?
- Splitting a continuous variable into equal sized groups
- customize ggplot2 axis labels with different colors
- How to extract the first n rows per group?
- Get filename without extension in R
- Select every nth row from dataframe
- R round to nearest .5 or .1
- What is the difference between parent.frame() and parent.env() in R; how do they differ in call by reference?
- Is it possible to define the “mid” range in scale_fill_gradient2()?
- R keep rows with at least one column greater than value
- How to use map from purrr with dplyr::mutate to create multiple new columns based on column pairs
- Sourcing R script over HTTPS
- Conditional cumsum with reset
- render dropdown for single column in DT shiny
- Programmatically creating Markdown tables in R with KnitR
- how to realize countifs function (excel) in R
- Create counter of consecutive runs of a certain value
- R strsplit with multiple unordered split arguments?
- Reorder rows using custom order
- Calculating percentile of dataset column
- modifying ggplot objects after creation
- R: xtable and dates
- Using R to read out excel-colorinfo
- Existing function for seeing if a row exists in a data frame?
- Convert comma separated string to integer in R
- Interpolating timeseries