【发布时间】:2014-08-04 15:23:42
【问题描述】:
我有一个数据框 data,其中包含有关 tiff 的信息,包括一列 txt 描述 tiff 的内容。不幸的是,txt 并不总是正确的,我们需要手动更正它们。因此,我想遍历数据中的每一行,显示 tiff 并寻求反馈,然后将其放入 data$txt.cor。
setwd(file.choose())
一些测试tiffs(里面有废话,但为了展示这个想法......):
txt <- sample(100:199, 5)
for (i in 1:length(txt)){
tiff(paste0(i, ".tif"))
plot(txt[i], ylim = c(100, 200))
dev.off()
}
和数据框:
pix.files <- list.files(getwd(), pattern = "*.tif", full.names = TRUE)
pix.file.info <- file.info(pix.files)
data <- cbind(txt, pix.file.info)
data$file <- row.names(pix.file.info)
data$txt.cor <- ""
data$txt[5] <- 200 # wrong one
我的反馈功能(错误处理被剥离):
read.number <- function(){
n <- readline(prompt = "Enter the value: ")
n <- as.character(n) #Yes, character. Sometimes we have alphanumerical data or leading zeros
}
现在是循环,非常感谢您的帮助:
for (i in nrow(data)){
file.show(data[i, "file"]) # show the image file
data[i, "txt.cor"] <- read.number() # aks for the feedback and put it back into the dataframe
}
在我的第一次尝试中,我想到了 plot.lm 的想法,您可以在按回车后浏览诊断图。我怀疑情节和tiffs不是大朋友。 file.show 原来更容易。但是现在我很难处理那个循环......
【问题讨论】: