Commit 3088d486 authored by Quentin Read's avatar Quentin Read
Browse files

fxn to replace na in data tables

parent 08a9a0ac
......@@ -2,5 +2,6 @@
export(group_nest_dt)
export(read.csv.better)
export(replace_na_dt)
export(unnest_dt)
import(data.table)
#' Replace NA in a data table
#'
#' Modified from a function written by Matt Dowle
#' See answer at https://stackoverflow.com/questions/7235657/fastest-way-to-replace-nas-in-a-large-data-table
#'
#' @export
replace_na_dt = function(DT, cols = names(DT), replace_with = 0) {
for (i in cols)
DT[is.na(get(i)), (i) := replace_with]
}
......@@ -4,7 +4,7 @@
\alias{group_nest_dt}
\title{Nest a data.table by group}
\usage{
group_nest_dt(dt, ..., .key = "data")
group_nest_dt(dt, ..., .key = "data", group_vars = NULL)
}
\description{
This function was originally written by TS Barrett in a document available at https://osf.io/f6pxw/download.
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/replace_na_dt.R
\name{replace_na_dt}
\alias{replace_na_dt}
\title{Replace NA in a data table}
\usage{
replace_na_dt(DT, cols = names(DT), replace_with = 0)
}
\description{
Modified from a function written by Matt Dowle
See answer at https://stackoverflow.com/questions/7235657/fastest-way-to-replace-nas-in-a-large-data-table
}
......@@ -4,7 +4,7 @@
\alias{unnest_dt}
\title{Unnest a nested data.table}
\usage{
unnest_dt(dt, col, id)
unnest_dt(dt, col, id, id_vars = NULL)
}
\description{
This function was written by TS Barrett in a document available at https://osf.io/f6pxw/download.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment