View source: R/valReplacement.R
sReplace | R Documentation |
The function is not intended for direct use. Once called by replaceVals it firstly checks for index presence in lookup. Upon the result of this check, the function moves along the branches of a decision tree (see Details).
sReplace(x, y0, uv)
x, y0 |
Data.tables |
uv |
Character vector or list of same length as x, containing unique names of involved columns in data. |
The function starts by checking the presence of a User-made index in lookup.
The function calls the helper whichDups to find the duplicated values in data. Also, looks for missing values set for multiple replacements and for eventual splits on missing data. In case of mixed simple/multiple requests the function splits lookup into maximum 3 subsets: one for simple replacements, for which it creates an internal index, one for multiple replacements of duplicated values for which it creates an internal index, and one for multiple replacements of missing values for which an internal index is not necessary.
The internal index contains row numbers corresponding to all the elements of distinct subsets of duplicated values
found within each involved data column and loops the function data.table::set()
to perform replacements on these
columns.
As mentioned above, no index is created for multiple replacements of missing values as there is only one generic value
per data column. The missing values data subset is then reshaped, and the columns are coalesced (see data.table
Manual) with corresponding data columns, for each generic value entered in lookup.
As stated above, simple replacements of unique values without User-made index are possible. Once the internal index created, the subset is reshaped, joined with the data on index and the corresponding columns are coalesced.
The function subsets the lookup using the special index values 0 and/or NA (or empty). At maximum, 3 subsets of lookup are formed as above. The replacement process is similar with the process used for absent index with the difference that simple replacements already have User-made index.
Following the decision tree described above, the function calls utility's helpers and functions imported from the data.table package to process all lookup requests, in one single run.
A named list containing updated involved columns in x, count of multiple replacements of duplicated values (if requested), count of multiple replacements of missing values (if requested).
dcast, fcoalesce, merge, set
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.