Converting wide tables into long tables

The opposite of gather() is spread(), which converts a long table into a wide table by converting the values in the key column into column headers, as shown:

 spread_df <- spread(gathered, "Keys", "Values") spread_df # Note that this in essence restores the original look alignment of the table # # A tibble: 50 x 10 # Region Name Area Frost `HS Grad` Illiteracy Income `Life Exp` Murder Population # <fctr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> # 1 Northeast Connecticut 4862 139 56.0 1.1 5348 72.48 3.1 3100 # 2 Northeast Maine 30920 161 54.7 0.7 3694 70.39 2.7 1058 # 3 Northeast Massachusetts 7826 103 58.5 1.1 4755 71.83 3.3 5814 ## unite ## The unite function is used to merge two or more ...

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.