[英]R. Error with read.table and paste(). Function is sticking FALSE from stringsAsFactors = F to object
我在外部硬盤Apple筆記本電腦中有一個目錄:
setwd("/Volumes/HD/1000Genomes/phased_IMPUTE2")
我想對一些文件運行一個for循環:
for(i in 1:22) {
infile1 <-
paste("chr",i,"_cancer.impute.hap",
sep="", stringsAsFactors = F) #
infile2 <-
paste("chr",i,"_cancer.impute.legend",
sep="", header = T, stringsAsFactors = F)
outfile <-
paste("chr",i,"_cancer_phased.txt",sep=" ")
hap <- read.table(infile1)
leg <- read.table(infile2)
# Perform more tasks...
}
但是,我收到以下消息:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file
'chr1_cancer_impute.hapFALSE': No such file or
directory
似乎paste()函數正在粘貼stringsAsFactors = F的“ FALSE”。我一定在犯一些非常愚蠢的錯誤。 有人知道發生了什么嗎? 非常感謝
調用paste
,不需要stringsAsFactor
選項,因為輸出將始終是字符。 只需使用沒有paste
即可:
paste0("chr", 5, "_cancer.impute.hap")
[1] "chr5_cancer.impute.hap"
從我所看到的情況來看, stringsAsFactor
似乎被忽略了,但是FALSE
值隨后被包含在串聯中,從而導致當前輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.