the below code finds the most recently modified file within a folder. Can anyone advise please how this can be amended to instead find the penultimate/second to last file that was modified? Can the which.max be amended to search for a -1 or is alternative code required?
#Open latest file
#get a vector of all filenames
files <- list.files(path="MYFILEPATH",pattern="files.xls",full.names = TRUE,recursive = TRUE)
#get the directory names of these (for grouping)
dirs <- dirname(files)
#find the last file in each directory (i.e. latest modified time)
lastfiles <- tapply(files,dirs,function(v) v[which.max(file.mtime(v))])
File_List <- file.info(list.files("//MYFILEPATH", full.names = T))
Path_Of_Interest <- rownames(File_List)[which.max(File_List$mtime)]