I have a data.table with automatically generated column names. The names take the form:
N.x.y.z
Where N is a character (literally N), and the remaining variables are integers.
I also have a .csv which associates iterations of x with meaningful strings. As in:
| X | Name |
|---|---|
| 1 | Model |
| 3 | Mileage |
What I would like to do is regenerate the column names in the format:
N.Name.y.z
I've tried to work along the lines of extracting the column names first, like
thefile = fread('filepath')
xx <- colnames(thefile)
colindex <- read.csv('the other file path')
colindex[,1] <- paste0('N.', colindex[,1], '.') #Converting x to N.x.
I messed around with grepl, replace_at, splitting the string up by '.'
Created on 2024-03-18 with reprex v2.0.2