how to pivot/unpivot (cast/melt) data frame? [duplicate]
This question already has an answer here: Reshaping data.frame from wide to long format 6 answers How can I 'unpivot' a table? What is the proper technical term for this? UPDATE: The term is called melt I have a data frame for countries and data for each year Country 2001 2002 2003 Nigeria 1 2 3 UK 2 NA 1 And I want to have something like Country Year Value Nigeria 2001 1 Nigeria 2002 2 Nigeria 2003 3 UK 2001 2 UK 2002 NA UK 2003 1 I still can't believe I beat Andrie with an answer. :) > library(reshape) > my.df <- read.table(text = "Country 2001 2002 2003 + Nigeria 1 2 3 + UK 2 NA 1", header