fast_round {dataPreparation}R Documentation

Fast round

Description

Fast round of numeric columns in a data.table. Will only round numeric, so don't worry about characters. Also, it computes it column by column so your RAM is safe too.

Usage

fast_round(data_set, cols = "auto", digits = 2, verbose = TRUE)

Arguments

data_set

matrix, data.frame or data.table

cols

List of numeric column(s) name(s) of data_set to transform. To transform all numerics columns, set it to "auto" (characters, default to "auto")

digits

The number of digits after comma (numeric, default to 2)

verbose

Should the algorithm talk? (logical, default to TRUE)

Details

It is performing round by reference on data_set, column by column, only on numercial columns. So that it avoid copying data_set in RAM.

Value

The same datasets but as a data.table and with numeric rounded.

Examples

# First let's build a very large data.table with random numbers
require(data.table)
M <- as.data.table(matrix(runif (3e4), ncol = 10))

M_rouded <- fast_round(M, 2)
# Lets add some character
M[, stringColumn := "a string"]

# And use our function
M_rouded <- fast_round(M, 2)
# It still work :) and you don't have to worry about the string.

[Package dataPreparation version 1.0.4 Index]