Probably,
round(a/b)*b
will do the work.
> a <- seq(.1,1,.13)
> b <- c(.1,.1,.1,.2,.3,.3,.7)
> data.frame(a, b, out = round(a/b)*b)
a b out
1 0.10 0.1 0.1
2 0.23 0.1 0.2
3 0.36 0.1 0.4
4 0.49 0.2 0.4
5 0.62 0.3 0.6
6 0.75 0.3 0.6
7 0.88 0.7 0.7
More Related Contents:
- Formatting Decimal places in R
- Round up from .5
- How to make a great R reproducible example
- How to join (merge) data frames (inner, outer, left, right)
- Why are these numbers not equal?
- Dynamically select data frame columns using $ and a character value
- Error: could not find function … in R
- Simultaneously merge multiple data.frames in a list
- Count number of rows within each group
- Drop unused factor levels in a subsetted data frame
- Use dynamic name for new column/variable in `dplyr`
- Select rows from a data frame based on values in a vector
- Combine a list of data frames into one data frame by row
- Issue when passing variable with dollar sign notation ($) to aes() in combination with facet_grid() or facet_wrap()
- Test if a vector contains a given element
- Counting the number of elements with the values of x in a vector
- How can I remove all duplicates so that NONE are left in a data frame?
- strptime, as.POSIXct and as.Date return unexpected NA
- Controlling number of decimal digits in print output in R
- Why is it not advisable to use attach() in R, and what should I use instead?
- Create an empty data.frame
- What does “The following object is masked from ‘package:xxx'” mean?
- How do you specifically order ggplot2 x axis instead of alphabetical order? [duplicate]
- Export data from R to Excel
- Confusion between factor levels and factor labels
- How to sort a character vector where elements contain letters and numbers?
- How should I deal with “‘someFunction’ is not an exported object from ‘namespace:somePackage'” error? [closed]
- What does “S3 methods” mean in R?
- How to get help in R?
- R: How to split a data frame into training, validation, and test sets?