Created
January 5, 2018 05:20
-
-
Save Ram-N/1e5509ed448cae77e3e3e0dfb0882e16 to your computer and use it in GitHub Desktop.
TIDYR - gather, unite and spread.
This file contains hidden or 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
library(tidyr) | |
df <- data.frame( | |
MKT=c("ABIORD", "ABIBOS", "GCFPQR", "ABIORD", "ABIBOS", "GCFPQR", "ABIORD", "ABIBOS", "GCFPQR"), | |
VERSION=c(1,2,3,4,1,2,3,4,1), | |
REVERSALS=c(7,6,7,7,7,6,7,7, 9), | |
NEIGH=c(1,2.3,3.3,4,3.3,2,1,3.3,4.3), | |
DIFFMETRIC=c(1.1,2.1,3.1,4.1,3.1,2.1,1.1,3.1,4.1)) | |
df %>% gather("key", "value", 3:5) %>% # long format, leaving just MKT and VERSION as row identifiers | |
unite(new, VERSION, key) %>% #create new combined col_names | |
spread(key = new, value = value) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment