2017-08-05 15 views
0

私はRを習得し、学習段階にあります。ヒストグラムと頻度ポリゴンコードをプロットしているときにエラーが発生しています。私はそれをデバッグすることができません。エラーの理解にご協力ください。無効な 'times'引数の助けが必要

#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") 

答えて

0

問題は、異なる長さのベクトルを使用していることです。 repplotは、2つの入力ベクトルの項目数が同じであると想定しています。

これを試してみて、私は変更を行った場所を見て:

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") 

enter image description here

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) 

enter image description here

+0

あなたは私が必要な修正:) –

+0

グレートを作っHAVB感謝!問題が解決した場合は、回答の左側にあるチェックマークをクリックして質問を終了してください。 – HAVB

関連する問題