knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

In this package we re-implemented R’s gather, spread, and drop_na functions that exist in tidyverse.

Functions

my_gather(data, keyname="key",valuename="value",chosen_cols)

Transform a data from wide to long by combining columns. For selected columns, put the columns names into a column of keys, and the values into a column of values.

my_spread(data, keycol, valcol)

Transform a data from long to wide. Select a ‘key’ column whose content will be the names of the new columns. Select a ‘value’ column whose content will be the values of the new columns.

my_dropna(input_dataframe)

Remove rows that contain NA values from a data frame.

Examples

# load the package
library(miniTidyR)
# example for my_dropna
df1 <- data.frame(A = c(12,25,NA,45), B = c(12,NA,30,45))
my_dropna(df1)
# example for my_gather
df2 <- data.frame(Groups = c("A","B"), Married = c(12,25), Other = c(100,55))
my_gather(df2, "Status", "Count", list("Married","Other"))
# example for my_spread
df3 <- data.frame(Name = c("A","A","B","B"), key = c("Age","Weight","Age","Weight"), value = c(45,80,30,70))
my_spread(df3,'key','value')


UBC-MDS/miniTidyR documentation built on May 7, 2019, 7:14 p.m.