This question already has an answer here:
I would like to change the orientation of my data frame.
I have following data:
df <- data.frame(name=c("Anna","Ben","Charlie"),
"year2017"=c("1", "2", "3"),
"year2018"=c("4", "1", "2"),
"year2019"=c("4", "2", "1"),
stringsAsFactors = F)
The data frame I would like to create should look like that:
name year
Anna 1
Anna 4
Anna 4
Ben 2
Ben 1
Ben 2
Charlie 3
Charlie 2
Charlie 1
Is there a way to get to this alignment of the data? Thanks in advance!