knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)

R-CMD-check Codecov test coverage License: MIT CRAN status

newdata

Introduction

newdata is an R package to generate new data frames for predictive purposes. By default, all specified variables vary across their range while all other variables are held constant at the default reference value. Types, classes, factor levels and time zones are always preserved. The user can specify the length of each sequence, require that only observed values and combinations are used and add new variables.

Consider the following observed data frame.

library(newdata)

obs_data

Length of Sequences

By default all variables are held constant (length of 1).

xnew_data(obs_data)

Specifying a variable causes it to vary sequentially across its range.

xnew_data(obs_data, int)

The user can specify the length of each sequence.

xnew_data(obs_data, xnew_seq(int, length_out = 3))

Observed Values and Combinations

The user can also indicate whether only observed values should be used in the sequence.

xnew_data(obs_data, xnew_seq(int, length_out = 3, obs_only = TRUE))

The xobs_only() function can be used to filter out unobserved values after the sequence has been generated.

xnew_data(obs_data, xobs_only(xnew_seq(int, length_out = 3)))

With two or more variables all combinations are used.

xnew_data(obs_data, int, fct)

To only get observed combinations use xobs_only()

xnew_data(obs_data, xobs_only(int, fct))

Add New Variables

Adding a new variable is simple.

xnew_data(obs_data, new = c(TRUE, FALSE))

Casting Variables

Casting variables is easy.

xnew_data(obs_data, xcast(int = 7, dbl = 10L, fct = "a rarity"))

Installation

To install the latest release version from CRAN.

install.packages("newdata")

To install the latest development version from r-universe.

install.packages("newdata", repos = c("https://poissonconsulting.r-universe.dev", "https://cloud.r-project.org"))

To install the latest development version from GitHub

# install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/stable/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))
pak::pak("poissonconsulting/newdata")

Contribution

Please report any issues.

Pull requests are always welcome.

Code of Conduct

Please note that the newdata project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



poissonconsulting/newdata documentation built on Jan. 18, 2024, 1:30 a.m.