Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
change format from wide to long
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