I am looking for a way to reshape my data:
> test
policyID startYear product
1: G000246-000 2014 Product 1
2: G000246-000 2014 Product 2
3: G000246-000 2014 Product 3
4: G000246-000 2015 Product 1
5: G000246-000 2015 Product 2
6: G000246-000 2015 Product 3
to this:
policyID 2014 2015
1: G000246-000 Product 1 Product 1
2: G000246-000 Product 2 Product 2
3: G000246-000 Product 3 Product 3
I have tried:
reshape(test, idvar = "policyID", timevar = "startYear", direction = "wide")
but i get:
policyID product.2014 product.2015
1: G000246-000 Product 1 Product 1
Whats the best approach to get to my desired results?
DATA:
structure(list(policyID = c("G000246-000", "G000246-000", "G000246-000",
"G000246-000", "G000246-000", "G000246-000"), startYear = c(2014,
2014, 2014, 2015, 2015, 2015), product = c("Product 1", "Product 2",
"Product 3", "Product 1", "Product 2", "Product 3")), row.names = c(NA,
-6L), class = c("data.table", "data.frame"))