나는이 도움이 될 것입니다 알고 해달라고
하지만 난 할 방법 중 하나입니다
##Step 1 read files
mycsv = dir(pattern=".csv")
n <- length(mycsv)
mylist <- vector("list", n)
for(i in 1:n) mylist[[i]] <- read.csv(mycsv[i],header = T)
그때 useually 단지 예를 들어, 일을 변경하는 기능을 적용 사용
## Change coloumn name
mylist <- lapply(mylist, function(x) {names(x) <- c("type","date","v1","v2","v3","v4","v5","v6","v7","v8","v9","v10","v11","v12","v13","v14","v15","v16","v17","v18","v19","v20","v21","v22","v23","v24","total") ; return(x)})
## changing type coloumn for weekday/weekend
mylist <- lapply(mylist, function(x) {
f = c("we", "we", "wd", "wd", "wd", "wd", "wd")
x$type = rep(f,52, length.out = 365)
return(x)
})
and so on.
나는 내가 만든 모든 변경 후에 다음 코드를 다시 저장합니다. 원래 파일 이름을 분할하고 각 파일의 이름을 파일 이름의 일부로 변경하여 각각의 indi를 추적 할 수있는 유용한 경우도 있습니다. 복수 파일 나중에)
## for example some of my file had a pattern in file name such as "201_E424220_N563500.csv",so I split this to save with a new name like this:
mylist <-lapply(1:length(mylist), function(i) {
mylist.i <- mylist[[i]]
s = strsplit(mycsv[i], "_" , fixed = TRUE)[[1]]
d = cbind(mylist.i[, c("type", "date")], ID = s[1], Easting = s[2], Northing = s[3], mylist.i[, 3:ncol(mylist.i)])
return(d)
})
for(i in 1:n)
write.csv(file = paste("file", i, ".csv", sep = ""), mylist[i], row.names = F)
나는 이것이 도움이되기를 바란다. PLYR 패키지에 대해 읽으면서 시간을내어 주시면 매우 유용 할 것입니다. 많은 데이터 분석 옵션이있는 매우 유용한 패키지입니다. 당신이 모든 CSV를 읽고처럼 simething 데이터 프레임을 반환 할 ldply을 사용할 수 있습니다 예를 들어
## l_ply split list, apply function and discard result
## ldply split list, apply function and return result in data frame
## laply split list, apply function and return result in an array
: 그래서 여기
data = ldply(list.files(pattern = ".csv"), function(fname) {
j = read.csv(fname, header = T)
return(j)
})
J를 사용하여 데이터 프레임됩니다 PLYR는 다음과 같은 기능을 적용있다 모든 csv 파일 데이터.
감사합니다. Ayan
아마도 'read.table' 대신'read.csv'가 필요할 수 있습니다. 그러나 파일이 어떻게 보이는지 (예 : 입력 및 의도 한 출력) 어떤 생각이든간에, 당신을 도울 수 없습니다. – Thomas
적절한 매개 변수를'read.table'에 전달해야합니다. – Roland