Coder Social home page Coder Social logo

r_tidyr_cheatsheet's Introduction

R_tidyr_cheatsheet

Installation :

# Tidyr Package Cheatsheet

## Installing the package
```R
install.packages("tidyr")
library(tidyr)

Basics Functions :

billboard

  • billboard - Song rankings for Billboard top 100 in the year 2000
library(tidyverse)

billboard_data <- tibble(
  song = c("Song1", "Song2", "Song3"),
  rank = c(1, 2, 3)
)

Chop and Unchop

  • chop - hopping and unchopping preserve the width of a data frame, changing its length. chop() makes df shorter by converting rows within each group into list-columns.
chopped_data <- chop(billboard_data)
unchopped_data <- unchop(chopped_data)

cms_patient_care

  • cms_patient_care - Data from the Centers for Medicare & Medicaid Services
cms_patient_care_data <- cms_patient_care

cms_patient_experience

  • cms_patient_experience - Data from the Centers for Medicare & Medicaid Services
cms_patient_experience_data <- cms_patient_experience

complete

  • complete - Complete a data frame with missing combinations of data
complete_data <- complete(billboard_data, song = c("Song1", "Song2", "Song3"))

construction

  • construction - Completed construction in the US in 2018
construction_data <- construction

crossing

  • crossing - Expand data frame to include all possible combinations of values
crossing_data <- crossing(x = c("A", "B"), y = c(1, 2))

drop_na

  • drop_na - Drop rows containing missing values
data_without_na <- drop_na(billboard_data)

expand

  • expand - Expand data frame to include all possible combinations of values
expanded_data <- expand(billboard_data, song = c("Song1", "Song2", "Song3"), rank = 1:3)

expand_grid

  • expand_grid -Create a tibble from all combinations of inputs
expanded_grid_data <- expand_grid(song = c("Song1", "Song2", "Song3"), rank = 1:3)

extract

  • extract - Extract a character column into multiple columns using regular expression groups
extracted_data <- extract(billboard_data, song, into = c("artist", "title"), regex = "(.*) - (.*)")

fill

  • fill - Fill in missing values with previous or next value
filled_data <- fill(billboard_data, rank)

fish_encounters

  • fish_encounters- Fish encounters
fish_encounters_data <- fish_encounters

full_seq

  • full_seq - Create the full sequence of values in a vector
full_sequence <- full_seq(1:5, period = 2)

gather

  • gather - Gather columns into key-value pairs
gathered_data <- gather(billboard_data, key = "attribute", value = "value", -song)

hoist

  • hoist - Hoist values out of list-columns
hoisted_data <- hoist(tibble(x = list(1, 2, 3)))

household

  • household - Household data
household_data <- household

nest

  • nest - Nest rows into a list-column of data frames
nested_data <- nest(billboard_data, data = -song)

nesting

  • nesting - Expand data frame to include all possible combinations of values
nested_data_expanded <- nesting(billboard_data, song = c("Song1", "Song2", "Song3"), rank = 1:3)

nest_legacy

  • nest_legacy - Legacy versions of 'nest()' and 'unnest()'
nested_data_legacy <- nest_legacy(billboard_data, data = -song)

pack

  • pack - Pack and unpack
packed_data <- pack(billboard_data)
unpacked_data <- unpack(packed_data)

pivot_longer

  • pivot_longer - Pivot data from wide to long
longer_data <- pivot_longer(billboard_data, cols = rank, names_to = "position", values_to = "rank")

pivot_wider

  • pivot_wider - Pivot data from long to wide
wider_data <- pivot_wider(longer_data, names_from = "position", values_from = "rank")

population

  • population - World Health Organization TB data
population_data <- population

relig_income

  • relig_income- Pew religion and income survey
relig_income_data <- relig_income

replace_na

  • replace_na - Replace NAs with specified values
data_with_replaced_na <- replace_na(billboard_data, list(rank = 0))

separate

  • separate - Separate a character column into multiple columns with a regular expression or numeric locations.
separated_data <- separate(billboard_data, col = song, into = c("artist", "title"), sep = " - ")

separate_longer_delim

  • separate_longer_delim - Split a string into rows
separated_longer_data <- separate_longer_delim(billboard_data, col = song, sep = ",")

separate_longer_position

  • separate_longer_position - Split a string into rows
separated_longer_data <- separate_longer_position(billboard_data, col = song, sep = c(1, 3))

separate_rows

  • separate_rows- Separate a collapsed column into multiple rows
separated_rows_data <- separate_rows(billboard_data, col = song, sep = ",")

separate_wider_delim

  • separate_wider_delim - Split a string into columns
separated_wider_data <- separate_wider_delim(billboard_data, col = song, sep = ",")

separate_wider_position

  • separate_wider_position - Split a string into columns
separated_wider_data <- separate_wider_position(billboard_data, col = song, sep = c(1, 3))

separate_wider_regex

  • separate_wider_regex - Split a string into columns
separated_wider_data <- separate_wider_regex(billboard_data, col = song, regex = "(.*) - (.*)")

smiths

  • smiths - Some data about the Smith family
smiths_data <- smiths

spread

  • spread - Spread a key-value pair across multiple columns
spread_data <- spread(gathered_data, key = "attribute", value = "value")

table1

  • table1 - Example tabular representations
table1_data <- table1

table2

  • table2 - Example tabular representations
table2_data <- table2

table3

  • table3 - Example tabular representations
table3_data <- table3

table4a

  • table4a - Example tabular representations
table4a_data <- table4a

table4b

  • table4b - Example tabular representations
table4b_data <- table4b

table5

  • table5 - Example tabular representations
table5_data <- table5

uncount

  • uncount - "Uncount" a data frame
uncounted_data <- uncount(billboard_data, wt = rank)

unite

  • unite - Unite multiple columns into one by pasting strings together
united_data <- unite(billboard_data, col = "combined", song, rank, sep = " - ")

unnest

  • unnest - a list-column of data frames into rows and columns
unnested_data <- unnest(nested_data)

unnest_legacy

  • unnest_legacs - Legacy versions of 'nest()' and 'unnest()'
unnested_data_legacy <- unnest_legacy(nested_data_legacy)

unnest_longer

  • unnest_longer - Unnest a list-column into rows
unnested_longer_data <- unnest_longer(nested_data)

unnest_wider

  • unnest_wider - Unnest a list-column into columns
unnested_wider_data <- unnest_wider(nested_data)

unpack

  • unpack - Pack and unpack
packed_data <- pack(billboard_data)
unpacked_data <- unpack(packed_data)

us_rent_income

  • us_rent_income - US rent and income data
us_rent_income_data <- us_rent_income

who

  • who - World Health Organization TB data
who_data <- who

who2

  • who2 - World Health Organization TB data
who2_data <- who2

world_bank_pop

  • world_bank_pop - Population data from the World Bank
world_bank_pop_data <- world_bank_pop

r_tidyr_cheatsheet's People

Contributors

sahilwep avatar

Watchers

 avatar

Forkers

affan1002

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.