NA2x: Replace numeric missing values with mean of the column

Description Usage Arguments Value Examples

View source: R/NA2x.R

Description

Replace numeric missing values with mean of the column

Usage

1
NA2x(data, verbose = FALSE, fun = mean, trim = 0)

Arguments

data

a dataframe containing numeric variables (e.g double or integer).No default data selected, must be an argument.

verbose

the verbose argument indicates the output was successful, by default verbose = FALSE as this function was designed for small data sets. For larger data sets, verbose = TRUE may be useful to know the function is being applied to large data frames as the function will take longer. If TRUE, returns Processing successful.

fun

specifies the function to be applied to missing values. By default, fun refers to mean(.x). An alternative function can be specified (fun = f(x)).

trim

a fraction of outlying observations to be ignored when calculating for the replacement of NA. By default the trim is set to 0.

Value

NA2x replaces each numeric missing value with the default being the mean of that column.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Create a data frame with both numeric and character variables.
df <-data.frame(
 first = c("a", NA, "b", "c","d"),
 second = c(NA, 2, NA, 3, 4),
 third = c(10, NA, NA, 5, 6)
)


# Input data frame with missing values.
NA2x(df)

liamg15/ezTools documentation built on Jan. 1, 2021, 8:19 a.m.