Overview of tidyr function categories
mainThe tidyr API is organized into five main functional categories:
- Pivoting: Converts data between long and wide forms. Use
pivot_longer()andpivot_wider()(replaces the deprecatedgather()andspread()). - Rectangling: Transforms deeply nested lists (e.g., from JSON) into tidy tibbles. Key functions include
unnest_longer(),unnest_wider(), andhoist(). - Nesting/Unnesting: Converts grouped data into a form where each group is a single row containing a nested data frame, and vice versa. Key functions include
nest()andunnest(). - Splitting and Combining: Manipulates character columns. Use
separate_wider_delim(),separate_wider_position(), orseparate_wider_regex()to split one column into many, andunite()to combine multiple columns into one. - Handling Missing Values: Manages implicit and explicit missing values. Use
complete()to make implicit values explicit,drop_na()to remove missing values,fill()to replace missing values with adjacent ones, orreplace_na()to replace them with a specific known value.