Hi Data Wranglers,
I had used gather and spread earlier but here column name itself has 2 names and hence found it tricky.
Let's consider a data frame.
df <- data.frame( "Year" = c(2001:2010,2001:2010), "Car" = c(rep("BMW",10),rep("Benz",10)),
"IND 1" = c(1:10),"IND 2" = c(1:10),"IND 3" = c(1:10),"IND 4" = c(1:10),"IND 5" = c(1:10),"IND 6" = c(1:10),
"CHN 1" = c(1:10),"CHN 2" = c(1:10),"CHN 3" = c(1:10),"CHN 4" = c(1:10),"CHN 5" = c(1:10),"CHN 6" = c(1:10),
"ITL 1" = c(1:10),"ITL 2" = c(1:10),"ITL 3" = c(1:10),"ITL 4" = c(1:10),"ITL 5" = c(1:10),"ITL 6" = c(1:10))
is there a way to transform the data into hierarchy ?
Year > Car > Country > Code
Eg:
Columns would be:
Year, Car, Country, Code, Value
1st row would be:
2001, BMW, IND, 1, 1
thanks in advance
Happy weekend