我一直在嘗試將循環的結果寫入csv。我試圖在20列的每一列中對數據進行排名。我正在使用的循環是:在r中寫入結果循環的結果
for (i in 1:ncol(testing_file)) {
print(rank(testing_file[[i]]))
}
這可以工作並將預期結果打印到屏幕上。我已經嘗試了很多在各種討論中提出的方法來將這個結果寫入文件或數據框架,大部分沒有運氣。 我就包括我最有前途的鉛,它返回正確的數據只有一列,以「測試」的列標題:
for (i in 1:ncol(testing_file)) {
testing<- (rank(testing_file[[i]]))
testingdf <- as.data.frame(testing)
}
任何幫助,不勝感激!
謝謝你的建議。我試過這些選項,但得到的錯誤: 不支持使用矩陣或列索引 – Crissy
我發現了一個解決方案:testage < - data.frame(matrix(,nrow = 73,ncol = 20)) (測試文件) (testage)< - colnames(testing_file) – Crissy