[R]檔案處理

weixin_34208283發表於2016-09-30

  • 合併csv
path <- 'E:\\Data\\combine'
setwd(path)
dir(path)
name_table <- as.data.frame(dir(),stringsAsFactors = F) 
initial_data <-
  read.table(paste0(name_table$`dir()`[1]),
             header = TRUE,
             sep = ",")
for(k in 2:length(name_table$`dir()`))
{
    temp_data <-
      read.table(paste0(name_table$`dir()`[k]),
                 header = TRUE,
                 sep = ",")
    
    initial_data <- rbind(initial_data,temp_data)
}

  • 批量修改檔名(ps:修改鎖屏桌布到本地)
path <- 'C:\\Users\\HOHO\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets'
setwd(path)
dir(path)
fl <- as.data.frame(dir(),stringsAsFactors = F) 
fl_2 <- paste0(fl$`dir()`,".jpg")
fl <- dir()
fl_2 <- as.character(unlist(fl_2))
file.rename(fl, fl_2)

相關文章