首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在无效的“times”参数上需要帮助

在无效的“times”参数上需要帮助
EN

Stack Overflow用户
提问于 2017-08-06 00:13:38
回答 1查看 2K关注 0票数 0

我是R的新手,还处于学习阶段。在绘制直方图和频率多边形代码时,我遇到错误。我无法调试它。请帮助理解错误。

代码语言:javascript
运行
复制
#HISTOGRAM

x=seq(200,1200,by=200)
width=200
x
freq=c(6,16,24,20,10)
freq
lowerbound=x-(width/2)
upperbound=x+(width/2)
lowerbound
upperbound
lowerbound[1]

brks=c(lowerbound[1],upperbound)
brks

y = rep(x,freq) #getting error Error in rep(x, freq) : invalid 'times' argument

hist(y,breaks = brks,xlab = "Monthly Rent",ylab = "Families",main = "Histogram)")


#Frequency Polygon

x=seq(200,1200,by=200)
width=200
x
freq=c(6,16,24,20,10)
freq
x1=c(0,x,1400)
x1
f1=c(0,freq)

f1
plot(x1,f1)

#Error: Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ

#plot(x1,f1,"b",xlab="Rent",ylab = "Families",main="FP")
EN

回答 1

Stack Overflow用户

发布于 2017-08-06 00:37:49

问题是你使用的是不同长度的向量。repplot都希望这两个输入向量具有相同的项目数。

试试这个,看看我在哪里做了修改:

代码语言:javascript
运行
复制
x=seq(200,1200,by=200) 
width=200 
x 
#freq=c(6,16,24,20,10) 
freq=c(6,16,24,20,10, 5) # Added one more item, 5
freq 
lowerbound=x-(width/2) 
upperbound=x+(width/2) 
lowerbound 
upperbound 
lowerbound[1]

brks=c(lowerbound[1],upperbound) 
brks

y = rep(x,freq) # No more errors here

hist(y, breaks = brks,xlab = "Monthly Rent",ylab = "Families",main = "Histogram")

代码语言:javascript
运行
复制
x=seq(200,1200,by=200) 
x 
#freq=c(6,16,24,20,10)
freq=c(6,16,24,20,10,5,3) # Added two more items, 5 and 3
freq 
x1=c(0,x,1400) 
x1 
f1=c(0,freq)

f1 
plot(x1,f1)

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

https://stackoverflow.com/questions/45523972

复制
相关文章

相似问题

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