| coalesce | R Documentation |
Construct a vector with as few missing values as possible from a selected sequence of vectors.
coalesce(mat, ...) index.coalesce(mat, ...)
mat |
a vector or matrix. |
... |
additional vectors or matrices, must have the same number of
rows as |
For coalesce, a vector in which each element is determined by
selecting the first non-missing value in the order in which they are
specified in the argument list. The first step is to construct a matrix from
all arguments. The output is initially set to column 1; for any missing values
in the column, the data from column 2 are used and so on until all columns have
been searched or all missing values replaced.
For index.coalesce, an integer vector indicating which column from mat or
from the vectors or constant specified for ... produced the result in coalesce.
This function is most useful for creating a column in a dataset from related columns that represent different methods. For example, a single column of alkalinity may be desired when there are multiple columns of alkalinity determined by various methods.
coalesce(c(1,NA,NA,3), c(2,2,NA,2)) # should be: [1] 1 2 NA 3 coalesce(c(1,NA,NA,3), c(2,2,NA,2), 0) # should be: [1] 1 2 0 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.