Created
December 2, 2022 15:27
-
-
Save johnmackintosh/520c1503fb4840f4d07b3f71ca0cbbb4 to your computer and use it in GitHub Desktop.
remember when tidyr::gather was a piece of cake?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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