I have a series of df1 df2 data frames where each data frame follows this structure:
x <- c(1:5) y <- c(1:5) df1 <- data.frame("Row One"=x, "Row Two"=y)
Example output for df1:
Row.One Row.Two 1 1 2 2 3 3 4 4 5 5
I put each data frame in a list dfList <- list(df1,df2...)
Now I want to loop through each data frame object in this list to replace the column names using the following command:
a <- grep("One", colnames(df)) b <- grep("Two", colnames(df)) names(df)[a] <- "R1" names(df)[b] <- "R2"
How can I structure a loop in R, so that no matter how many data frames are in the list object, the column name change commands above will be applied to each data frame?
source share