I want to add a prefix to each column (except the first) in each dataframe in a list of dataframe. I have been taking the approach that I would used for a single dataframe and trying to use both lapply and Map without success.
I also want change the the first column of each dataframe by adding the name of the dataframe as a prefix to the existing name
A snippet of my list of dataframes
l1 <- list(Fe = structure(list(Determination_No = 1:6, `2` = c(55.94,
55.7, 56.59, 56.5, 55.98, 55.93), `3` = c(56.83, 56.54, 56.18,
56.5, 56.51, 56.34), `4` = c(56.39, 56.43, 56.53, 56.31, 56.47,
56.35), `5` = c(56.32, 56.29, 56.31, 56.32, 56.39, 56.32), `7` = c(56.48,
56.4, 56.54, 56.43, 56.73, 56.62), `8` = c(56.382, 56.258, 56.442,
56.258, 56.532, 56.264), `10` = c(56.3, 56.5, 56.2, 56.5, 56.7,
56.5), `12` = c(56.11, 56.46, 56.1, 56.35, 56.36, 56.37)), class = "data.frame", row.names = c(NA,
-6L)), SiO2 = structure(list(Determination_No = 1:6, `2` = c(7.63,
7.65, 7.73, 7.67, 7.67, 7.67), `3` = c(7.84, 7.69, 7.59, 7.77,
7.74, 7.64), `4` = c(7.67, 7.74, 7.62, 7.81, 7.66, 7.8), `5` = c(7.91,
7.84, 7.96, 7.87, 7.84, 7.92), `7` = c(7.77, 7.83, 7.76, 7.78,
7.65, 7.74), `8` = c(7.936, 7.685, 7.863, 7.838, 7.828, 7.767
), `10` = c(7.872684992, 7.851291827, 7.872684992, 7.722932832,
7.680146501, 7.615967003), `12` = c(7.64, 7.71, 7.71, 7.65, 7.82,
7.68)), class = "data.frame", row.names = c(NA, -6L)), Al2O3 = structure(list(
Determination_No = 1:6, `2` = c(2.01, 2.02, 2.03, 2.01, 2.02,
2), `3` = c(2.01, 2.01, 2, 2.02, 2.02, 2.03), `4` = c(2,
2.03, 1.99, 2.01, 2.01, 2.01), `5` = c(2.02, 2.02, 2.05,
2.03, 2.02, 2.03), `7` = c(1.88, 1.9, 1.89, 1.88, 1.88, 1.87
), `8` = c(2.053, 2.044, 2.041, 2.038, 2.008, 2.02), `10` = c(2.002830415,
2.021725042, 2.021725042, 1.983935789, 2.002830415, 2.021725042
), `12` = c(2.09, 2.05, 1.96, 2.09, 2.06, 2.02)), class = "data.frame", row.names = c(NA,
-6L)))
I have tried the following
colnames(l1[-1]) <- lapply(l1[-1],paste0("Lab-",colnames(l1[-1])))
colnames(l1[-1]) <- Map(paste("Lab",colnames(l1[-1]),sep=" "),l1[-1])
Using either solution I get the following error message
Error in get(as.character(FUN), mode = "function", envir = envir): object 'Lab-' of mode 'function' was not found