I am trying to work with poorly formatted SAP data.
In this source data, when one of the variables ("Profile" in the example) has more entries, they are stacked. This creates an empty observation with only the same "ID" in the next row.
As such:
ID Status Product Profile Description
154 NOCO 3000 A1 failure
215 ATCO 4000 dfect
164 NOCO 2000 A1 dfect
164 A2
875 ATCO 3000 failure
548 NOCO 2000 A1 dfect
548 A2
548 A3
797 NOCO 3000 failure
444 ATCO 4000 failure
What I would like to do is to move these stacked values and move them to the next column.
ID Status Product Profile Profile2 Profile3 Description
154 NOCO 3000 A1 failure
215 ATCO 4000 dfect
164 NOCO 2000 A1 A2 dfect
875 ATCO 3000 failure
548 NOCO 2000 A1 A2 A3 dfect
797 NOCO 3000 failure
444 ATCO 4000 failure
How would I go about doing this?
Thanks!
Edit:
Added dput of the first table above:
structure(list(ID = c(154L, 215L, 164L, 164L, 875L, 548L, 548L,
548L, 797L, 444L), Status = structure(c(3L, 2L, 3L, 1L, 2L, 3L,
1L, 1L, 3L, 2L), .Label = c("", "ATCO", "NOCO"), class = "factor"),
Product = c(3000L, 4000L, 2000L, NA, 3000L, 2000L, NA, NA,
3000L, 4000L), Profile = structure(c(2L, 1L, 2L, 3L, 1L,
2L, 3L, 4L, 1L, 1L), .Label = c("", "A1", "A2", "A3"), class = "factor"),
Description = structure(c(3L, 2L, 2L, 1L, 3L, 2L, 1L, 1L,
3L, 3L), .Label = c("", "dfect", "failure"), class = "factor")), .Names = c("ID",
"Status", "Product", "Profile", "Description"), class = "data.frame", row.names = c(NA,
-10L))