I am trying to make data wide. I know there are a couple of pages dedicated to making data wide, but I have tried all of their suggestions and it just did not work.
This is the data I have
Officer Company
Robert Abernathy Goldman Sachs
Robert Abernathy Walmart
Robert Abernathy CVS
Rex Adams Goldman Sachs
Rex Adams Dell
Marc Abramowitz Samsung
and I want this data to look like
Officer Company1 Company2 Company3
Robert Abernathy Goldman Sachs Walmart CVS
Rex Adams Goldman Sachs Dell NA
Marc Abramowitz Samsung NA NA
I thought I would be able to use the tidyr package and I did
> library(tidyr)
> ppn_wide<-spread(data=ppn1, key=Officer, value=Company)
Error: Duplicate identifiers for rows (12, 13), (20, 21), (36, 37), (40, 41), (75, 76), (116, 117), (141, 142), (149, 150), (158, 159), (189, 190), (207, 208), (244, 245), (249, 250), (264, 265), (267, 268), (273, 274), (328, 329), (339, 340), (346, 347, 348), (366, 367), (378, 379), (397, 398), (407, 408), (417, 418), (422, 423), (425, 426), (430, 431), (436, 437, 438), (450, 451), (461, 462), (481, 482), (486, 487), (491, 492), (496, 497, 498), (504, 505), (546, 547), (553, 554), (566, 567), (577, 578), (594, 595), (632, 633)'
So, I've tried this too
> reshape(ppn1, idvar="Officer", timevar="Company", direction="wide")
But then only the column officer remains and company disappears completely.
I have also tried using reshape and reshape2 packages, they don't work.
> ppn_wide<-cast(ppn1, officer~PPN.org)
Using officer as value column. Use the value argument to cast to override this choice
Error in `[.data.frame`(data, , variables, drop = FALSE) :
undefined columns selected
> ppn_wide<-dcast(ppn1, officer~PPN.org)
Using officer as value column: use value.var to override.
reshape2 package creates a data frame called ppn_wide but it looks nothing like the kind of data set that I want. It uses officers' names to indicate whether they hold a position in a company. Something like this,
officer Goldman Sachs Walmart Dell
Robert Abernathy Robert Abernathy Robert Abernathy NA
What is going on here?