1

「Colli_On」と「Colli_Off」というヘッダーを持つ2列の数字を含む単純なcsvファイルがあります。ファイル名と列名の 3 つの引数を渡す単純な Rscript を作成し、Bland Altman プロットを生成したいと考えています。ただし、次のエラーメッセージが表示されます

> Error in plot.window(...) : need finite 'xlim' values
Calls: baplot ... do.call -> plot -> plot.default -> localWindow -> plot.window
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf

どこが間違っていますか?

   #!/usr/bin/Rscript
# -*- mode: R =*-

#script passes 3 arguments filename and 2 columns and does bland altman analysis
#Example BA /home/moadeep/Data/sehcat.csv Colli_on Colli_off

args <- commandArgs(TRUE)
mydata <- read.csv(file=args[1],head=TRUE,sep="\t")

baplot = function(x,y){

  bamean = (x+y)/2
  badiff = (y-x)

  plot(badiff~bamean, pch=20, xlab="mean", ylab="difference")
# in the following, the deparse(substitute(varname)) is what retrieves the
# name of the argument as data
  title(main=paste("Bland-Altman plot of collimator x and y\n",
    deparse(substitute(x)), "and", deparse(substitute(y)),
    "standardized"), adj=".5")
#construct the reference lines on the fly: no need to save the values in new 
# variable names
  abline(h = c(mean(badiff), mean(badiff)+1.96 * sd(badiff),
    mean(badiff)-1.96 * sd(badiff)), lty=2)
} 

pdf(file="test.pdf")
baplot(mydata$args[2],mydata$argss[3])
dev.off()
4

1 に答える 1

2

問題は次の行にあります。

baplot(mydata$args[2],mydata$argss[3])

タイプミスについては言及しません... を要求するとmydata$args[2]、R は data.frame で「args」という名前の列を探します。明らかに、そのような列はないため、NULL. data.frame から列をプログラムで抽出する方法は、[. 正しい構文は次のとおりです。

baplot(mydata[args[2]],mydata[args[3]])

これで問題が解決するはずです。

(また、 とは異なり、存在しない列を抽出しようとすると、[演算子はエラーをスローすることに注意してください: 私見の好ましい機能です。)$

于 2012-12-09T01:06:07.417 に答える