library(rvest)

# create data frames for each section of data
data_A <- data.frame(
  protocol_url_segment = character(),
  A.1 = character(), A.2 = character(), A.3 = character(), A.3.1 = character(), A.3.2 = character(), A.4.1 = character(), A.5.1 = character(), A.5.2 = character(),  A.5.3 = character(), A.5.4 = character(), A.7 = character(), A.8 = character(),
  stringsAsFactors = FALSE
)
data_B <- data.frame(
  protocol_url_segment = character(),
  B.1.1 = character(), B.1.3.4 = character(), B.3.1.and.B.3.2 = character(), B.4.1 = character(), B.4.2 = character(), B.5.1 = character(),
  B.5.2 = character(), B.5.3.1 = character(), B.5.3.2 = character(), B.5.3.3 = character(), B.5.3.4 = character(), B.5.4 = character(),
  B.5.5 = character(), B.5.6 = character(),
  stringsAsFactors = FALSE
)
data_D <- data.frame(
  protocol_url_segment = character(),
  IMP_number = character(),
  D.1.2andD.1.3 = character(),  D.2.1 = character(),  D.2.1.1.1 = character(),  D.2.1.1.2 = character(),  D.2.1.2 = character(),
  D.2.5 = character(),  D.2.5.1 = character(),  D.3.1 = character(),  D.3.10.1 = character(),  D.3.10.2 = character(),  D.3.10.3 = character(),
  D.3.11.1 = character(),  D.3.11.10 = character(),  D.3.11.11 = character(),  D.3.11.12 = character(),  D.3.11.13 = character(),  D.3.11.13.1 = character(),
  D.3.11.2 = character(),  D.3.11.3 = character(),  D.3.11.3.1 = character(),  D.3.11.3.2 = character(),
  D.3.11.3.3 = character(),  D.3.11.3.4 = character(),  D.3.11.3.5 = character(),  D.3.11.3.5.1 = character(),  D.3.11.4 = character(),  D.3.11.5 = character(),  D.3.11.6 = character(),
  D.3.11.7 = character(),  D.3.11.8 = character(),  D.3.11.9 = character(),  D.3.2 = character(),
  D.3.4 = character(),  D.3.4.1 = character(),  D.3.7 = character(),  D.3.8 = character(),  D.3.9.1 = character(),  D.3.9.2 = character(),  D.3.9.3 = character(),
  D.3.9.4 = character(),  D.8.1 = character(),  D.8.3 = character(),  D.8.4 = character(),  stringsAsFactors = FALSE
)
data_E <- data.frame(
  protocol_url_segment = character(),
  E.1.1 = character(), E.1.1.1 = character(), E.1.1.2 = character(), E.1.2A = character(), E.1.2B = character(), E.1.2C = character(), E.1.2D = character(), E.1.2E = character(), E.1.3 = character(),
  E.2.1 = character(), E.2.2 = character(), E.2.3 = character(), E.2.3.1 = character(),  E.3 = character(),  E.4 = character(),
  E.5.1 = character(), E.5.1.1 = character(),  E.5.2 = character(), E.5.2.1 = character(),
  E.6.1 = character(), E.6.10 = character(), E.6.11 = character(), E.6.12 = character(), E.6.13 = character(), E.6.13.1 = character(),
  E.6.2 = character(), E.6.3 = character(), E.6.4 = character(), E.6.5 = character(), E.6.6 = character(), E.6.7 = character(), E.6.8 = character(), E.6.9 = character(),
  E.7.1 = character(), E.7.1.1 = character(), E.7.1.2 = character(), E.7.1.3 = character(), E.7.1.3.1 = character(),  E.7.2 = character(),  E.7.3 = character(),  E.7.4 = character(),
  E.8.1 = character(), E.8.1.1 = character(), E.8.1.2 = character(), E.8.1.3 = character(), E.8.1.4 = character(), E.8.1.5 = character(), E.8.1.6 = character(), E.8.1.7 = character(), E.8.1.7.1 = character(),
  E.8.2.1 = character(), E.8.2.2 = character(), E.8.2.3 = character(), E.8.2.3.1 = character(),  E.8.2.4 = character(),  E.8.3 = character(),  E.8.4 = character(), E.8.4.1 = character(),
  E.8.5 = character(), E.8.5.1 = character(),  E.8.6.1 = character(), E.8.6.2 = character(), E.8.6.3 = character(),  E.8.7 = character(),  E.8.8 = character(),
  E.8.9.1D = character(), E.8.9.1M = character(), E.8.9.1Y = character(),  E.8.9.2D = character(), E.8.9.2M = character(), E.8.9.2Y = character(),
  stringsAsFactors = FALSE
)
data_F <- data.frame(
  protocol_url_segment = character(),
  F.1.1A = character(), F.1.1B = character(), F.1.1.1 = character(), F.1.1.1.1 = character(), F.1.1.2 = character(), F.1.1.2.1 = character(),
  F.1.1.3 = character(), F.1.1.3.1 = character(), F.1.1.4 = character(), F.1.1.4.1 = character(), F.1.1.5 = character(), F.1.1.5.1 = character(),
  F.1.1.6 = character(), F.1.1.6.1 = character(), F.1.2 = character(), F.1.2.1 = character(), F.1.3 = character(), F.1.3.1 = character(),
  F.2.1 = character(), F.2.2 = character(), F.3.1 = character(), F.3.2 = character(), F.3.3 = character(), F.3.3.1 = character(),
  F.3.3.2 = character(), F.3.3.3 = character(), F.3.3.4 = character(), F.3.3.5 = character(), F.3.3.6 = character(),
  F.3.3.6.1 = character(), F.3.3.7 = character(), F.3.3.7.1 = character(), F.4.1 = character(), F.4.2.1 = character(), F.4.2.2 = character(),
  F.5 = character(),
  stringsAsFactors = FALSE
)
data_G <- data.frame(
  protocol_url_segment = character(),
  network_number = character(),
  G.4.1 = character(),  G.4.3.4 = character(),
  stringsAsFactors = FALSE
)
data_H <- data.frame(
  protocol_url_segment = character(),
  H.4.1 = character(),
  stringsAsFactors = FALSE
)
data_N <- data.frame(
  protocol_url_segment = character(),
  N.A = character(),  N.B = character(),  N.C = character(),  N.D = character(),  N.E = character(),
  stringsAsFactors = FALSE
)
data_P <- data.frame(
  protocol_url_segment = character(),
  P.A = character(),  P.B = character(),
  stringsAsFactors = FALSE
)

# specify the base URL of the protocol page
protocol_url_segment <- "2015-003589-10/GR"
base_url <- "https://www.clinicaltrialsregister.eu/ctr-search/trial/"
url <- paste0(base_url, protocol_url_segment)

# read in the HTML content of the page
page <- read_html(url)

# extract the tricell rows as a list of nodes
tricell_rows <- page %>% html_nodes("tr.tricell")

# function to extract the text from row td elements and create a row vector 
extract_td_text <- function(row) {
  td_elements <- html_children(row)
  td_texts <- sapply(td_elements, html_text)
  td_texts <- trimws(td_texts)
  return(as.vector(td_texts))
}

# extract the text from the td elements in each row and store them in rows_list
rows_list <- lapply(tricell_rows, extract_td_text)

# create a data frame from the rows_list
tricell_df <- do.call(rbind.data.frame, c(rows_list, stringsAsFactors = FALSE))
colnames(tricell_df) <- c("Column1", "Column2", "Column3")

# Create a data frame with the codes and their corresponding replacements
lookup_df <- data.frame(
  code = c("E.8.9.1", "E.8.9.1", "E.8.9.1", "E.8.9.2", "E.8.9.2", "E.8.9.2", "F.1.1", "F.1.1", "N.", "N.", "N.", "N.", "N.", "P.", "P.", "E.1.2", "E.1.2", "E.1.2", "E.1.2", "E.1.2", "B.3.1 and B.3.2", "D.1.2 and D.1.3"),
  value = c("In the Member State concerned days", "In the Member State concerned months", "In the Member State concerned years", "In all countries concerned by the trial days", "In all countries concerned by the trial months", "In all countries concerned by the trial years", "Trial has subjects under 18", "Number of subjects for this age range:", "Competent Authority Decision", "Date of Competent Authority Decision", "Date of Ethics Committee Opinion", "Ethics Committee Opinion of the trial application", "Ethics Committee Opinion: Reason(s) for unfavourable opinion", "Date of the global end of the trial", "End of Trial Status", "Classification code", "Level", "System Organ Class", "Term", "Version", "Status of the sponsor", "IMP Role"),
  replacement = c("E.8.9.1D", "E.8.9.1M", "E.8.9.1Y", "E.8.9.2D", "E.8.9.2M", "E.8.9.2Y", "F.1.1A", "F.1.1B", "N.A", "N.B", "N.C", "N.D", "N.E", "P.A", "P.B", "E.1.2A", "E.1.2B", "E.1.2C", "E.1.2D", "E.1.2E", "B.3.1andB.3.2", "D.1.2andD.1.3")
)

# Loop through each row in the target data frame and check if the code and value match
for (i in 1:nrow(tricell_df)) {
  code <- tricell_df[i, 1]
  value <- tricell_df[i, 2]
  replacement <- lookup_df[lookup_df$code == code & lookup_df$value == value, "replacement"]
  # If a match is found, replace the code with the corresponding replacement
  if (length(replacement) > 0) {
    tricell_df[i, 1] <- replacement
  }
}

# Function that filters dataframe by the first letter in ‘Column1’ and returns the filtered dataframe
filter_by_first_letter <- function(df, letter) {
  index <- grep(paste0("^", letter), df$Column1)
  filtered_df <- df[index,]
  return(filtered_df)
}

# Filter the dataframe for each letter, then create separate dataframes
df_A <- filter_by_first_letter(tricell_df, "A")
df_B <- filter_by_first_letter(tricell_df, "B")
df_D <- filter_by_first_letter(tricell_df, "D")
df_E <- filter_by_first_letter(tricell_df, "E")
df_F <- filter_by_first_letter(tricell_df, "F")
df_G <- filter_by_first_letter(tricell_df, "G")
df_H <- filter_by_first_letter(tricell_df, "H")
df_N <- filter_by_first_letter(tricell_df, "N")
df_P <- filter_by_first_letter(tricell_df, "P")


_____________

That's my code so far. I now want it to input the data in the "df_" dataframes (df_A, df_B, etc) into the "data_" dataframes. But these two sets of dataframes are structured differently.
"data_" dataframes have headers with each code.
"df_" dataframes, have these codes in the first column and the values in the third column.
The values in the "df_" dataframes should be inserted as a row in the "data_" dataframe.