I have several CSV
files for each year. Each file contains the same variables and observations.
df14 <- data.frame(name = c("one", "two", "three"), A = c(1,2,3), B = c(4, 2, 1), C = c(0, 1, 1))
df15 <- data.frame(name = c("one", "two", "three"), A = c(3,1,1), C = c(0, 0, 1), B = c(8, 5, 5))
Suppose df14
& df15
represent years 2014 & 2015 respectively.
Note: the variables are not recorded in the same order.
What I'd like to do is see how each variable (A, B, C) are changing by year for each name
.
Is there a way to combine these in one data frame? Should I simply rbind
them?
Update:
One thing I could do is assign the years as a new variable and rbind
but is it good practice?
df14$year <- 2014; df15$year <- 2015
df <- rbind(df14, df15)
which gives:
name A B C year one 1 4 0 2014 two 2 2 1 2014 three 3 1 1 2014 one 3 8 0 2015 two 1 5 0 2015 three 1 5 1 2015