R data.table keys

Hello
Can you have in data.table the first row as the key column to combine variables and the second row with the real variable names? I need to harmonise 10 tables and all of them have different variable names. I made the keys to harmonise, but I need to keep the original colnames as well. So far everything I do changes the column names and keeps only the keys.

So shortly, is it possible to have two rows of column names?

library(tidyverse)
library(lubridate)
library(forcats)
library(stringr)
library(data.table)
library(rio)
library(dplyr)

1. Keys

keys1 <- c("SDC_GENDER","SDC_CHILD_NB","LAB_CRP","PM_HIP")
keys2 <- c("SDC_GENDER","SDC_CHILD_NB","LAB_CRP","PM_HIP")

2.

data.table example with variable names.

TD3 = data.table(q128 = c(1, 2, 1, 2), q129 = c(1, 5, 2, 4), q130 = c(0.8, 3.0, 10.0, NA), q131 = c(55, 56, 80, 79))
TD3
TD4 = data.table(q128 = c(1, 1, 1, 2), q129 = c(1, 3, 2, 999), q130 = c(0.9, 3.1, NA, 9.0), q131 = c(58, 60, 45, NA))
TD4

Hope, I made the example the right way :no_mouth:. First time.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.