mkt2: Make tibble (data frame) for two groups

View source: R/utils.R

mkt2R Documentation

Make tibble (data frame) for two groups

Description

Make tibble from two vectors x and y. The two vectors are re-organised in a data frame with column 1 for group labels as factors and column 2 for observations.

Usage

mkt2(
  x,
  y,
  gr_names = "gr",
  obs_names = "obs",
  group_labels = c("Group1", "Group2")
)

Arguments

x, y

Two vectors.

gr_names

The name of the first column - default "gr" for groups.

obs_names

The name of the second column - default "obs" for observations.

Value

A tibble - see details in tibble.

Examples

# Generate two vectors
g1 <- rnorm(10)
g2 <- rnorm(10)

# Make tibble using default parameters
df <- mkt2(g1, g2)

# Make tibble using custom parameters
df <- mkt2(g1, g2, gr_names = "groups", obs_names = "values", group_labels =
c("group1", "group2"))

# For instance, vectors x & y:
x <- c(1, 2, 3, 4, 5)
y <- c(11, 12, 13, 14, 15)
df <- mkt2(x, y)
# become a tibble: 10 × 2:
       gr   obs
   <fctr> <dbl>
1  Group1     1
2  Group1     2
3  Group1     3
4  Group1     4
5  Group1     5
6  Group2    11
7  Group2    12
8  Group2    13
9  Group2    14
10 Group2    15

GRousselet/rogme documentation built on Nov. 12, 2022, 4:38 a.m.