I have a data frame which I need to transform. I need to change the unique rows into single columns based on the value of a column.
My data below:
df1 <- data.frame(V1 = c("a", "a", "b", "b","b"),
V2 = c("product1", "transport", "product1", "product2","transport"),
V3 = c("100", "10", "100", "100","10"))
> df1
V1 V2 V3
1 a product1 100
2 a transport 10
3 b product1 100
4 b product2 100
5 b transport 10
I need the following transformation and the division of the value of V3 into the number of products included in V1.
> df2
V1 V2 transport V3
1 a product1 10 100
2 b product1 5 100
3 b product2 5 100