I'm working with job application data where each prior job held is a row in an excel file. I want to transform the data set such that there are columns for each past employer 1,2,3,4 etc...
I think the problem is best explained with an example. How do I get from the start data frame to the desired data frame?
I've tried some melting and casting but I'm getting stuck because I don't want a column created for each unique company name, but rather based on the number of unique company names.
id <- c(1000,1000,1002,1007,1007,1007,1007,1009)
employers <-c("Ikea","Subway","DISH","DISH","Ikea","Starbucks","Google","Google")
start_date <- c("2/1/2013","5/1/2000","4/1/2012","3/1/2014","8/15/2011","4/15/2008","2/1/2004","3/15/2010")
start <- data.frame(cbind(id,employers,start_date))
colnames(start) <- c("id","employers","start_date")
start
unique_id <- c(1000,1002,1007,1009)
emp1 <- c("Ikea","DISH","DISH","Google")
emp2 <- c("Subway",NA,"Ikea",NA)
emp3 <- c(NA,NA,"Starbucks",NA)
emp4 <- c(NA, NA,"Google",NA)
emp1_start <- c("2/1/2013","4/1/2012","3/1/2014","3/15/2010")
emp2_start <- c("5/1/2000",NA,"8/15/2011",NA)
emp3_start <- c(NA,NA,"4/15/2008",NA)
emp4_start <- c(NA,NA,"2/1/2004",NA)
desired <- data.frame(cbind(unique_id,emp1,emp2,emp3,emp4,emp1_start,emp2_start,emp3_start,emp4_start))
desired