Apologies, returning to lists
and dataframes
in R
after a while, so have forgotten my way about. Suppose that I have several dataframes in a list:
d2<- data.frame(week=c("12th","13th","14th"),value=c(1,20,100))
d1<- data.frame(week=c("12th","13th","14th"),value=c(1,10,15))
d3<- data.frame(week=c("12th","13th","14th"),value=c(1,220,30))
dfList<- list(d1,d2,d3)
dfList
[[1]]
week value
1 12th 1
2 13th 10
3 14th 15
[[2]]
week value
1 12th 1
2 13th 20
3 14th 100
[[3]]
week value
1 12th 1
2 13th 220
3 14th 30
And I would like to have a final dataframe with combined data, the shape of which is as follows
finalDf<- data.frame(week=c("12th","13th","14th"),value1=c(1,20,100),value2=c(1,10,15),value3=c(1,220,30))
week value1 value2 value3
1 12th 1 1 1
2 13th 20 10 220
3 14th 100 15 30
How could I achieve the above form of data? Also, what if my initial dataframes also have NAs, which I would like to remove prior to achieving the final form of data?
Many, many thanks.