Description Usage Arguments Details Value Examples
Perform an operation of choice on a data.table (in-place): (i) replace na/inf values (ii) replace zero values (iii) replace missing values (e.g. " ").
1 2 |
data |
Data.table which is to be modified in place (data.table). |
replace |
Value used to replace the existing values (character) [Default: Mode-specific (see above)] |
col |
Vector of column names which are to be modified (vector - character) [Default: All columns in the data]. |
mode |
Value which is to be replaced ((i) 'na_inf' (replace: Na, inf, -inf -> 0) (ii) 'zero' (replace: 0 -> NA), (iii) 'missing' (replace: " "* -> NA) (character). |
Maintained by: Clara Marquardt
data.table modified in place
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | sample_data <- copy(ehR_cohort)
sample_data[, ':='(test_col=prediction, test_col_1=feature_categorical_3)]
## replace: na_inf
sample_data[c(1,3,4), ':='(test_col=c(NA, -Inf, NA), test_col_1=NA)]
print(sample_data)
replace_na_zero_missing(data=sample_data, replace="na_inf", col=c("test_col"))
print(sample_data)
## replace: zero
sample_data[c(1,3,4), ':='(test_col=0, test_col_1=0)]
print(sample_data)
replace_na_zero_missing(data=sample_data, replace="zero", col=c("test_col_1"))
print(sample_data)
## mode - missing
sample_data[, ':='(test_col=as.character(test_col), test_col_1=as.character(test_col_1))]
sample_data[c(1,3,4), ':='(test_col=" ", test_col_1=" ")]
print(sample_data)
replace_na_zero_missing(data=sample_data, replace="missing")
print(sample_data)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.