Skip to content

Instantly share code, notes, and snippets.

@johnmackintosh
Created December 2, 2022 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmackintosh/520c1503fb4840f4d07b3f71ca0cbbb4 to your computer and use it in GitHub Desktop.
Save johnmackintosh/520c1503fb4840f4d07b3f71ca0cbbb4 to your computer and use it in GitHub Desktop.
remember when tidyr::gather was a piece of cake?
### old way
```r
df %>%
mutate(row = row_number()) %>%
gather('column', 'source', -row, -N) # key = column, value = source, retain row and N
# further transforms
```
### new way
```r
df %>%
mutate(row = row_number()) %>%
pivot_longer(!c(row , N), names_to = 'column', values_to = 'source')
# further transforms
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment