knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(relper)
library(dplyr)
library(ggplot2)

count2

The goal of count2 is to count the number of observations, giving a initial count.

count2(mtcars,cyl)

count_na

The goal of count_na is to count the number of missing observations.

count_na(c(2,2,NA))

count_na(c(2,2,2))

cut_by_quantile

The goal of cut_by_quantile is to divide a numeric variable by a set of quantiles.

set.seed(123);x <- rnorm(100)

quartiles <- seq(0,1,by = .25)

table(cut_by_quantile(x,q = quartiles))

expand_grid_unique

The goal of expand_grid_unique is to create a grid of all combination from two variables, with no repetition of pairs, not matter the position.

expand_grid_unique(x = 1:3,y = 1:3)

You can also set the argument include_equals to TRUE, so equal pairs are kept.

expand_grid_unique(x = 1:3,y = 1:3, include_equals = TRUE)

obj_to_string

The goal of obj_to_string is to return the name of an R object as a string.

x <- c(1,2,3,5,7,8,12,100)

obj_to_string(x)

replace_boolean

The goal of replace_boolean is to replace the values of a boolean variable to other values.

replace_boolean(c(T,T,T,F,F),1,2)

replace_na

The goal of replace_na is to replace the NA value to another.

replace_na(c(NA,NA,NA),1)

row_number_unique

The goal of row_number_unique is to get the row number, but considering the unique values of a variable.

tibble(x = c(1,1,1,2,3,4,5,5)) %>% 
  mutate(
    row_number = row_number(),
    row_number_unique = row_number_unique(x)
  )

rpearson

The goal of rpearson is to simulate data, where two variables will be linear correlated with a normal distribution, using pearson correlation coefficient as an argument.

set.seed(123);df <- rpearson(n = 100, pearson = .85, mean = 3)

df %>% 
  ggplot(aes(x,y))+
  geom_point()+
  geom_smooth(method = "lm", se = FALSE)+
  plt_theme_xy()


vbfelix/relper documentation built on May 10, 2024, 10:50 p.m.