I have two dataframes containing farming revenue data. One is in the following format: 

```
dataframe_1 <- read.table(
  text = "ID    2000   2001   2002   2003   2004
          Barley  180    143    434    232    656
          Wheat   764    667    667    554    121
          Oats    121    443    343    346    121",
  header = TRUE,
  check.names = FALSE
)

```

And a second empty dataframe, laid out in the format:

```
dataframe_2 <- read.table(
  text = "ID    2000   2001   2002   2003   2004
          Barley  NA     NA     NA     NA     NA
          Wheat   NA     NA     NA     NA     NA
          Oats    NA     NA     NA     NA     NA",
  header = TRUE,
  check.names = FALSE
)

```

The first data frame contains a huge amount of unnecessary information and I want to grab the data that is useful and summarize it in the second table.

I want to write a function that checks for matching column headers and row names and takes the corresponding value from the first table, and places it in the second.

Example: if column in both tables is named "2002" and rows are named "Wheat", replace the NA value in the second table with the value 667.

I have been attempting to use a nested for loop:

```
date_range <- c("2000", "2001", "2002", "2003", "2004")

for (y in rownames(dataframe_2)) {
  for (x in date_range) {
    dataframe_1[[x]][y] <- dataframe_2[[x]][y]
  }
}

```

But simply receive unhelpful error messages that do not clarify the problem and the data frames are unchanged. One example being: 

```
Error in `[[<-.data.frame`(`*tmp*`, x, value = c(NA_real_, NA_real_, NA_real_,  : 
  replacement has 73 rows, data has 72

```