-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
122 lines (91 loc) · 3.73 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# newdata <img src="man/figures/logo.png" align="right" alt= "Poisson Consulting logo"/>
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R-CMD-check](https://github.com/poissonconsulting/newdata/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/newdata/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/gh/poissonconsulting/newdata/graph/badge.svg?token=pJO8edj5Wu)](https://codecov.io/gh/poissonconsulting/newdata)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit)
[![CRAN status](https://www.r-pkg.org/badges/version/newdata)](https://cran.r-project.org/package=newdata)
<!-- badges: end -->
## Introduction
`newdata` is an R package to generate new data frames by varying some variables while holding the others constant.
By default, all specified variables vary across their range
while all other variables are held constant at a reference value.
The user can specify the length of each sequence, require that only
observed values and combinations are used and add new variables.
Types, classes, factor levels and time zones are always preserved.
Consider the following observed 'old' data frame.
```{r}
library(newdata)
newdata::old_data
```
### Length of Sequences
By default all variables are set to a reference value.
```{r}
xnew_data(old_data)
```
Specifying a variable causes it to vary sequentially across its range.
```{r}
xnew_data(old_data, int)
```
The user can specify the length of each sequence.
```{r}
xnew_data(old_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.
```{r}
xnew_data(old_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.
```{r}
xnew_data(old_data, xobs_only(xnew_seq(int, length_out = 3)))
```
When two or more variables are specified all combinations are used.
```{r}
xnew_data(old_data, int, fct)
```
To only get observed combinations use `xobs_only()`
```{r}
xnew_data(old_data, xobs_only(int, fct))
```
### Add New Variables
Adding a new variable is simple.
```{r}
xnew_data(old_data, extra = c(TRUE, FALSE))
```
### Casting Variables
Casting variables to be the same class as the original is achieved as follows.
```{r}
xnew_data(old_data, xcast(lgl = 1, int = 7, dbl = 10L, fct = "a rarity", hms = "00:00:02"))
```
## Installation
To install the latest release version from CRAN.
```r
install.packages("newdata")
```
To install the latest development version from [r-universe](https://poissonconsulting.r-universe.dev/newdata).
```r
install.packages("newdata", repos = c("https://poissonconsulting.r-universe.dev", "https://cloud.r-project.org"))
```
or from [GitHub](https://github.com/poissonconsulting/newdata)
```r
# install.packages("remotes")
remotes::install_github("poissonconsulting/newdata")
```
## Contribution
Please report any [issues](https://github.com/poissonconsulting/newdata/issues).
[Pull requests](https://github.com/poissonconsulting/newdata/pulls) are always welcome.
## Code of Conduct
Please note that the newdata project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.