簡體   English   中英

R. read.table和paste()錯誤。 函數將FALSE從stringAsFactors = F粘貼到對象

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM