I am using financial data and the row names of my main dataframe are dates.
> assets[1:3,1:5]
ALD SFN TCO KIM CTX
2003-01-03 48.1 23.98 23.5 23 22.34
2003-01-06 48.1 23.98 23.5 23 22.34
2003-01-07 48.1 23.98 23.5 23 22.34
I would like to add a column (here I want to add FOC$close to assets) from a dataframe that is of same type but some dates are missing :
> FOC[1:3,1:2]
Close Adj.Close
2003-01-03 510 510
2003-01-07 518 518
The missing values should just be NA's, so it would look like that :
> assets[1:3,1:6]
ALD SFN TCO KIM CTX FOC
2003-01-03 48.1 23.98 23.5 23 22.34 510
2003-01-06 48.1 23.98 23.5 23 22.34 NA
2003-01-07 48.1 23.98 23.5 23 22.34 518
Is there a nice way to do that? I managed to do something similar with rows by doing something like
> rowtoadd <- list(ALD=18.1,...)
> dataframe[nrow(dataframe) + 1, names(rowtoadd)] <- rowtoadd
but I am not able to do this for columns.