I have a dataframe named df1
which has four columns (i.e. id
, s
, date
and value
). The value column is empty and I want to fill it using a second dataframe that is named df2
. df2
is filled with id
column and many other columns that are named using dates which they belong. All I need is to find corresponding values of df1$value
in df2
, where both dates and id numbers are matching.
Example data:
set.seed(123)
#df1
df1 <- data.frame(id = 1:100,
s = runif(100,100,1000),
date = sample(seq(as.Date('1999/01/01'), as.Date('2001/01/01'), by="day"), 100),
value = NA)
#df2
df2 <- data.frame(matrix(runif(80000,1,100), ncol=800, nrow=100))[-1]
names(df2) <- seq(as.Date("1999-01-01"),as.Date("2002-12-31"),1)[c(1:799)]
df2 <- cbind(id = 1:100, df2)