我正在嘗試重新組織一些數據。這裏是文件的描述:控制檯在R中的循環之後無響應
60 csv files
40 columns
250 rows
我想要做的是刪除無用的列,使其更具可讀性。我選擇用循環做到這一點。我的代碼:
file.number <- paste0(rep(c(1:30), each = 2), rep(c('a','b')), '.csv') # lists file names (works fine)
d1 <-setNames(lapply(file.number, read.csv, stringsAsFactors=FALSE),paste(file.number)) # imports data into r (works fine)
i = 1
while (i <= length(file.number)){
index <- i # indexs
nam <- paste0("d2",i) # creates new file name (same problem with this line of code removed)
d2 <- subset(d1[[index]], select = c('column.1','column.2','column.2')) # If i run this line of code outside the loop by just indexing a specific file it runs fine, it just doesn't work in the loop
assign(nam, d2) # creates a new file name (I run into the same problem with this line of code removed
}
因此,當我運行此循環時,R控制檯變得無響應。我已經運行循環非常類似於此,沒有問題。有誰知道這個問題可能是什麼?