I have a dataset with two rows as columns, I would like to melt the dataset in order to have just 6 columns (country , date, var1, var2, var3, var4). Below a sample code to understand. Thanks for the help.
# what i have
date_or <- c("2001 q1", "2001 q2", "2001 q3","2001 q4")
AT <- c("var1","1","2","3")
AT1 <- c("var2","1","2","3") #in the real dataset is the same name as column ("AT")
AT2 <- c("var3","1","2","3") #in the real dataset is the same name as column ("AT")
AT3 <- c("var4","1","2","3") #in the real dataset is the same name as column ("AT")
BE <- c("var1","1","2","3")
BE1 <- c("var2","1","2","3") #in the real dataset is the same name as column ("BE")
BE2 <- c("var3","1","2","3") #in the real dataset is the same name as column ("BE")
BE3 <- c("var4","1","2","3") #in the real dataset is the same name as column ("BE")
dt_or <- data.frame(date_or, AT, AT1, AT2, AT3)
head(dt_or)
# what I would like to obtain
date <- c("2001 q1", "2001 q2", "2001 q3","2001 q4"
,"2002 q1","2002 q2","2002 q3","2002 q4")
country <- c("AT","AT","AT","AT",
"BE","BE","BE","BE",
"DE","DE","DE","DE",
"ES","ES","ES","ES")
feature <- c("var1","var2", "var3", "var4"
,"var1","var2", "var3", "var4"
,"var1","var2", "var3", "var4"
,"var1","var2", "var3", "var4")
value <- c(seq(1,16,1)) # as for example
dt <- data.frame(date, country, feature, value)