폴더에 많은 파일이 있고 그 중 많은 파일이 비어 있고 다른 파일에는 데이터가 있습니다.
내가하려는 것은 다음과 같습니다.
#Load all data in a list
file_all <- list.files(file.path(getwd(), "testall"), pattern = "\\.txt$")
이 목록을 사용하여 @nrussell에 설명 된 방법을 사용하여 빈 파일을 건너 뛰려고 합니다. R에서 텍스트 파일을 가져올 때 빈 파일을 건너 뛰는 방법은 무엇입니까?
library(plyr)
df_list <- lapply(files, function(x) {
if (!file.size(x) == 0) {
list.files(x)
}
})
그리고 (빈 파일이 아님)
df_list2 <- lapply(files, function(x) {
if (file.size(x) == 0) {
list.files(x)
}
})
@nrussell과 내 것의 차이점은 빈 파일 목록과 빈 파일이 아닌 다른 목록을 만들고 싶다는 것입니다. 비어있는 파일 수와 비어 있지 않은 파일 수를 알고 싶습니다.
# create a list of files in the current working directory
list.of.files <- file.info(dir())
# get the size for each file
sizes <- file.info(dir())$size
# subset the files that have non-zero size
list.of.non.empty.files <- rownames(list.of.files)[which(sizes != 0)]
# here you can further subset that list by file name, eg - if I only want all the files with extension .mp3
list.of.non.empty.files[grep( ".mp3", list.of.non.empty.files)]
# get the empty files
list.of.empty.files <- rownames(list.of.files)[which(sizes == 0)]
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다