eval(expr,envir,enclos)中的错误:找不到对象'y'

时间:2014-01-16 20:39:33

标签: r plot points

我会尽量保持格式正确,问题清楚。这是我的代码:

require(MASS)
require(splines)

graphics.off()

knots <- c(40,120)
xx <- seq(1,180,by=6)

bs.x <- bs(xx,knots=knots,degree=3)


mydata <- read.table("flux2data.txt")
class(mydata)
y1 <- t(mydata[1,])

(当我在终端中运行上述3行时,它输出:

            1
V1  178.11460
V2  173.62679
V3  194.84784
V4  193.06830
V5  218.38292
V6  211.21930
V7  202.13962
V8  209.85012
V9  246.57999
V10 290.12267
V11 382.94236
V12 435.97783
V13 394.26406
V14 320.12048
V15 258.65543
V16 197.68100
V17 202.39585
V18 168.58327
V19 160.03192
V20 162.61306
V21 123.30684
V22 154.49358
V23 177.47395
V24 195.91601
V25 205.67455
V26 136.63245
V27  88.99387
V28 150.76973
V29 113.87477
V30 116.66087

已删除

plot(xx,y1,
     xlim=c(0,190),
     xlab="angle",ylab="y",
     main="Data")

yx <- data.frame(y = y1,x = bs.x)

bs.fit <- lm(y ~.,data=yx)

# add the fitted function to the plot
points(xx,bs.fit$fitted,pch="+",col="red")

text(0,100.23,"True function o",adj=0)
text(0,100.2,"Fitted function +",col="red",adj=0)

希望这看起来像我认为的那样清晰。无论如何,我遇到的错误是:

"Error in eval(expr, envir, enclos) : object 'y' not found"

它可以很好地绘制我的数据。然而,它不会绘制一个b样条拟合,我相信它应该是。任何帮助都会很棒!

由于

以下是我的数据的输入(y1)的输出:

structure(c(178.114604, 173.626787, 194.847839, 193.068295, 218.382922, 
211.219296, 202.139618, 209.850119, 246.579992, 290.12267, 382.942357, 
435.977826, 394.264057, 320.12048, 258.655426, 197.680997, 202.395847, 
168.583267, 160.031924, 162.613059, 123.306841, 154.493579, 177.473953, 
195.916012, 205.674549, 136.632449, 88.993869, 150.769732, 113.874773, 
116.66087), .Dim = c(30L, 1L), .Dimnames = list(c("V1", "V2", 
"V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11", "V12", 
"V13", "V14", "V15", "V16", "V17", "V18", "V19", "V20", "V21", 
"V22", "V23", "V24", "V25", "V26", "V27", "V28", "V29", "V30"
), "1"))

0 个答案:

没有答案