I have a large number of csv files in a directory that I need to rename based off of corresponding cols in another index/reference data frame. Here is a three element sample of what I'm dealing with:
dir.create("dir1") write.csv(mtcars[1:2,], "dir1/20821659.csv", row.names=FALSE) write.csv(mtcars[3:4,], "dir1/20821654.csv", row.names=FALSE) write.csv(mtcars[5:6,], "dir1/20821657.csv", row.names=FALSE) Now I have another data frame with the orignial names of these files in one column, and another column that I would like to use to rename them:
location <- c("SFM01_2", "SFM05_2", "02M08_2") sn <- c("20821659", "20821654", "20821657") df<- data.frame(location, sn) For example, the location name that corresponds to the first file name (20821659) is SFM01_2, and I would like to change that file name to SFM01_2 and so on for all the many files in this folder.