Created
May 11, 2015 22:19
-
-
Save erzk/a495ac530124b8462f9f to your computer and use it in GitHub Desktop.
change format from wide to long
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
library(tidyr) | |
foreign_victims_wide <- read.csv("foreign_victims_wide.csv") | |
# reshape to long format | |
foreign_victims_long <- gather(foreign_victims_wide, Year, Victims, X1998:X2012) | |
# remove Xs | |
# could be omitted if using check.names=FALSE in read.csv() | |
foreign_victims_long$Year <- gsub("X", "", paste(foreign_victims_long$Year)) | |
write.csv(foreign_victims_long, file = "foreign_victims_long.csv", row.names=FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment