Last active
August 29, 2015 14:10
-
-
Save sithjaisong/3687705b8cb6190746d8 to your computer and use it in GitHub Desktop.
Stacking files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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