Skip to content

Instantly share code, notes, and snippets.

@sithjaisong
Last active August 29, 2015 14:10
Show Gist options
  • Save sithjaisong/3687705b8cb6190746d8 to your computer and use it in GitHub Desktop.
Save sithjaisong/3687705b8cb6190746d8 to your computer and use it in GitHub Desktop.
Stacking files
# Set the Directory
setwd("~/yourpath")
# Geting a List of Files
files <- listfiles(pattern= \\.text$')
# บางครั้ง อาจจะเจอกับ
info = file.info(files)
enpty = rownames(info[info$siz ==0, ])
# อันนี้อาจจะดูไม่ค่อยพบบ่อยเท่าไหร่ แต่ว่า คุณก็สามารถรวมไฟล์ได้ถ้าคนละสกุล
CSVs <- listfiles(pattern='csv')
TEXTs <- listfiles(pattern='txt)
mylist <- CSVs[!CSVs %in% TEXTs]
# Stacking files into a dataframe
cand_br <- do.call("rbind", lapply(files, FUN = function(files) {
read.table(files,
header=FALSE,
sep=";",stringsAsFactors = FALSE,
fileEncoding="cp1252",
fill = TRUE, blank.lines.skip = TRUE)
}
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment