我是R新手,需要創建一堆根據其來自的人羣命名的直方圖。當我嘗試運行沒有「名稱」部分的循環時,它工作正常。下面的代碼循環遍歷名稱列表並按順序應用它們,但我最終得到了3,364個具有相同直方圖的版本。如果有人有任何建議,我會很感激。嵌套循環創建根據列表命名的直方圖
popFiles <- list.files(pattern = "*.txt") # generates a list of the files I'm working with
popTables <- lapply(popFiles, read.table, header=TRUE, na.strings="NA")
popNames <- read.table(file.path("Path to file containing names", "popNamesR.txt"), header=FALSE,)
popNames <- as.matrix(popNames)
name <- NULL
table <- c(1:58)
for (table in popTables){
for (name in popNames){
pVals <- table$p
hist(pVals, breaks=20, xlab="P-val", main=name))
}
}
因爲循環內沒有任何順序發生,所以一次又一次地調用相同的直方圖。 – mtoto