Description Usage Arguments Details Examples
Given a data.frame
or data.table
, turns selected values into
a different value for specified columns. By default all columns are used, but
you may specify the onlyConvert argument with a vector of one or more columns
names and only do the conversion on these columns, or alternatively, specify
the noConvert argument with a vector of one or more columns names that
shouldnt have the conversion done on them. You may only choose to specify
onlyConvert or noConvert, you may not specify both at the same time.
1 2 |
data |
a data frame/table that we want to remove NAs from |
values |
a vector of one or more values that you wish to be converted into another value |
valueToConvertTo |
the value that you want values converted to |
onlyConvert |
optional - specify a vector of one or more column names as the only columns where the NA conversion will take place. You may either have this parameter satified, or the noConvert parameter specified, you may not specify both. |
noConvert |
optional - specify a vector of one or more columns names that you do not want any NA conversion applied to. You may either have this parameter satified, or the noConvert parameter specified, you may not specify both. |
ref |
TRUE (default) or FALSE, if TRUE and data is a data.table, modify the data.table by reference (modifying-in-place), if FALSE, do not modify the data.table by reference, instead treat it like a data.frame (copy on modify). |
This function uses seperate methods for data.tables and data.frames. By
default, data.tables will be modified by reference. To turn off this
behavior, set ref
to FALSE
.
1 2 3 4 5 6 7 8 9 | Lets say we want to convert "na" or -500 values into "jake" for only the
columns "town" and "city" in my_data:
\code{valuesToNA(my_data, c("na", -500), "jake",
onlyConvert = c("town", "city"))}
Or, what if we want to convert "na" or -500 values into "jake" for every
columnn in my_data except for "town", "city", or "country":
\code{valuesToNA(my_data, c("na", -500), "jake",
noConvert = c("town", "city", "country"))}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.