수정 경로와 1 년 중 매우 제한된 디렉토리가 주어집니다. 나는 각이 초기 조합 사이의 경로의 조합 (fixPath - 년)을 획득하기 위해 노력하고있어 및 다른, 비 고정 및 비 동일하게 수량, fixPath의 각 조합에 포함 된 하위 디렉토리 - 년for 루프의 각 반복에서 여러 출력을 저장하십시오.
fixPath <- "C:/Users/calcazar/Desktop/example"
year <- 2008:2010
pathVector <- paste(fixPath, year, sep = "/")
pathVector
[1] "C:/Users/calcazar/Desktop/example/2008" "C:/Users/calcazar/Desktop/example/2009"
[3] "C:/Users/calcazar/Desktop/example/2010"
이 문제를 해결하기 위해 내 접근 방식을 사용입니다
A의 루프 :
setwd(pathVector[1])
- 와 작업 디렉토리가 채워진 가방을 스캔 설정 루프의 각 반복에서 벡터에
paste(pathVector[1], list.files(pathVector[1]), sep = "/")
- 저장이 조합을하고 다음 반복
진행 ...하지만 : 그 작업 디렉토리에 list.files
와 ES (하위 디렉토리) 및 각 조합에 당첨되는 것 조합 수는 많아서 각 반복마다 하나 이상의 저장 방법을 알아낼 수 없습니다..
for (i in seq_along(pathVector)) {
setwd(pathVector[i])
# here I only obtain the combination of the last iteration
# and if I use pathFinal[i] I only obtain the first combination of each iteration
pathFinal <- paste(pathVector[i], list.files(pathVector[i]), sep = "/")
# print give me all the combinations
print(pathFinal[i])
}
그래서, 방법 for 루프의 각 반복에서 여러 값 (조합)을 저장할 수 있습니다 : 여기 내 코드는?
나는 예를 들어, 모든 조합을 포함하는 벡터를 원하는 :
"C:/Users/calcazar/Desktop/example/2008/a"
"C:/Users/calcazar/Desktop/example/2008/z"
"C:/Users/calcazar/Desktop/example/2009/b"
"C:/Users/calcazar/Desktop/example/2009/z"
"C:/Users/calcazar/Desktop/example/2009/y"
"C:/Users/calcazar/Desktop/example/2010/u"
'list.files (full.names = TRUE, recursive = TRUE)'이 작업에 도움이 되나요? – roman
아니요, 작동하지 않습니다. 'full.names = TRUE'와'recursive = TRUE'를 어떻게 적용 할 수 있습니까? 'list.files (fixPath, full.names = TRUE, recursive = TRUE)와 작동하지 않기 때문에' –
list.files (fixPath, recursive = TRUE, include.dirs = TRUE)'완벽하게 작동합니다! –