Skip to contents

Creates a forward fill UpdateByOp that replaces null values in cols with the last known non-null values. This operation is forward only.

Arguments

cols

String or list of strings denoting the column(s) to operate on. Can be renaming expressions, i.e. “new_col = col”. Default is to perform a forward fill on all non-grouping columns.

Value

UpdateByOp to be used in a call to update_by().

Details

This function acts on aggregation groups specified with the by parameter of the update_by() caller function. The aggregation groups are defined by the unique combinations of values in the by columns. For example, if by = c("A", "B"), then the aggregation groups are defined by the unique combinations of values in the A and B columns.

This function, like other Deephaven uby functions, is a generator function. That is, its output is another function called an UpdateByOp intended to be used in a call to update_by(). This detail is typically hidden from the user. However, it is important to understand this detail for debugging purposes, as the output of a uby function can otherwise seem unexpected.

For more information, see the vignette on uby functions by running vignette("update_by").

Examples

if (FALSE) { # \dontrun{
library(rdeephaven)

# connecting to Deephaven server
client <- Client$new("localhost:10000", auth_type = "psk", auth_token = "my_secret_token")

# create data frame, push to server, retrieve TableHandle
df <- data.frame(
  timeCol = seq.POSIXt(as.POSIXct(Sys.Date()), as.POSIXct(Sys.Date() + 0.01), by = "1 sec")[1:500],
  boolCol = sample(c(TRUE, FALSE), 500, TRUE),
  col1 = replace(sample(10000, size = 500, replace = TRUE), sample(500, 100), NA),
  col2 = replace(sample(10000, size = 500, replace = TRUE), sample(500, 100), NA),
  col3 = replace(1:500, sample(500, 100), NA)
)
th <- client$import_table(df)

# forward fill col1 and col2
th1 <- th$
  update_by(uby_forward_fill(c("col1", "col2")))

# forward fill col1 and col2, grouped by boolCol
th2 <- th$
  update_by(uby_forward_fill(c("col1", "col2")), by = "boolCol")

# forward fill col3, compute parity of col3, and forward fill col1 and col2, grouped by boolCol and parity of col3
th3 <- th$
  update_by(uby_forward_fill("col3"))$
  update("col3Parity = col3 % 2")$
  update_by(uby_forward_fill(c("col1", "col2")), by = c("boolCol", "col3Parity"))

client$close()
} # }