我正在尝试为函数和图形运行for循环。我有不同的向量(特征),我从数据中运行。我希望通过名为i的for循环运行每个特征,并将每个结果输出到一个具有相应特征名称的单独文件中,因此我只需运行该命令一次,而不是9次。该文件的名称("bristleX特征1.txt","bristleX特征2.txt",...,"bristleX特征i.txt")也应与.pdf命令相同。("bristleX特征1.pdf","bristleX特征2.pdf",...,"bristleX特征i.pdf")我在使用接收器和pdf函数时遇到了问题;它们不会输出与使用paste()函数的常规标题或名称相同的内容。在特征中使用i的函数只需要数字1到9就可以工作,但一次只能做一个。
library(qtl)
data("bristleX")
traits<-c(1:9)
for(i in traits){
sink(paste(file="bristleX trait",i".txt"))
pdf(paste(file = "brixtleX trait",i".pdf", paper="special",width = 8.5,
height = 11,
family="Times", pointsize=11,bg="white",fg="black"))
print("MR QTLs")
out.mr <- scanone(bristleX, pheno.col=i, method="mr") # estimate LOD
#for a single phenotype
summary(out.mr, threshold=3)
plot(out.mr) #
sink()
dev.off()
}
发布于 2018-05-29 06:07:58
我还没有试过你的例子,但是我可以看到你这里有一个错误:
...
sink(paste(file="bristleX trait",i".txt"))
pdf(paste(file = "brixtleX trait",i".pdf", paper="special",width = 8.5,
...
粘贴没有文件参数。你可能想要:
...
sink(file=paste("bristleX trait",i".txt"))
pdf(file = paste("brixtleX trait",i".pdf", paper="special",width = 8.5,
...
发布于 2018-05-29 06:17:01
你在过去的函数中有一个错误,你可以使用
paste("bristleXtrait",i,".txt")
而不是
paste("bristleXtrait",i".txt")
此外,您还必须替换文件名中的空格。您可以使用str_replace_all()
函数
sink(file = str_replace_all(paste("bristleX trait",i,".txt"), pattern=" ", repl=""))
https://stackoverflow.com/questions/50573730
复制相似问题