I'm trying to convert the following data with two string columns to expand from long to wide. What is the most efficient method in R to achieve the following:
Sample data:
data_sample <- data.frame(code=c(1,1,2,3,4,2,4,3),name=c("bill","bob","rob","max","mitch","john","bart","joe"),numberdata=c(100,400,300,-200,300,-500,100,-400))
Desired function to result in the following dataset:
data_desired <- data.frame(code=c(1,2,3,4),name1=c("bill","rob","max","mitch"),name2=c("bob","john","joe","bart"),numberdata1=c(100,300,-200,300),numberdata2=c(400,-500,-400,100))
I'm using big data (the real code is 1-100,000), is there an efficient data.table method to accomplish this? Thanks!