update: Update Data Set Based on Row Numbers

updateR Documentation

Update Data Set Based on Row Numbers

Description

Update a data.frame using specific integers for row numbers or a vectorised filter. Also supports dplyr groups. see Examples.

Usage

## S3 method for class 'data.frame'
update(object, rows, ...)

Arguments

object

a data.frame

rows

row numbers or a logical vector

...

arguments passed on to mutate()

Examples

iris |> 
  update(3:4, Species = c("A", "B")) |> 
  head()
  
iris |> 
  update(Species == "setosa" & Sepal.Length > 5,
         Species = "something else") |> 
  head()
  
if (require("dplyr")) {

  # also supports dplyr groups:
  iris |> 
    group_by(Species) |>
    # update every 2nd to 4th row in group
    update(2:4, Species = "test") |> 
    # groups will be updated automatically
    count()

}

certe-medical-epidemiology/certetoolbox documentation built on April 17, 2025, 3:24 a.m.