首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RScript中csv文件中的平淡奥特曼绘图

RScript中csv文件中的平淡奥特曼绘图
EN

Stack Overflow用户
提问于 2012-12-09 01:35:42
回答 1查看 639关注 0票数 1

我有一个简单的csv文件,其中包含2列标题为"Colli_On“和"Colli_Off”的数字。我已经写了一个简单的Rscript,它传递了3个参数-文件名和列名-并希望生成一个Bland Altman图。但是,我得到了以下错误消息

代码语言:javascript
复制
> 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

我哪里错了?

代码语言:javascript
复制
   #!/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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-09 09:06:07

问题出在这一行:

代码语言:javascript
复制
baplot(mydata$args[2],mydata$argss[3])

更别提打字错误了..。当您请求mydata$args[2]时,R在data.frame中查找名为"args“的列。显然,没有这样的列,所以你会得到NULL。从data.frame中提取列的编程方法是使用[。正确的语法应该是:

代码语言:javascript
复制
baplot(mydata[args[2]],mydata[args[3]])

这应该会解决你的问题。

(还要注意,与$不同的是,如果您试图提取不存在的列,[操作符将抛出错误:这是一个更可取的特性。)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13780012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档