2012-11-01 64 views
0

我在文件中的數據集,它看起來像這樣:分級十進制數據並繪製一個直方圖

0.0707526823 
0.4859753978 
0.0084166789 
0.0694709558 
0.0156410467 
0.3783259831 
0.8977261856 
0.7981824881 
0.2079852045 
0.9498437264 
0.9264972044 
0.1878358734 
0.0020816686 
0.0024611297 
0.4250464895 
0.0725748666 
0.0407962054 
0.8282363221 
0.8408343333 
0.7129760016 
0.2772250135 
0.3677588953 
0.4723908637 
0.9452814318 

我想斌這些數據與0.1的區間,並繪製柱狀圖。

我曾嘗試使用R,

,在這裏我在做什麼

x<-read.table("filex", header=T) 
breaks=seq (min, max, step) 
hist (x$col1, breaks) 

,但該命令沒有在我的情況:(

在awk中的任何一個內襯,或R工作歡迎

謝謝

+1

你對這個錯誤非常含糊。 「但這個命令不起作用,在我的情況下:(」不是一個合適的錯誤描述 – Roland

+0

它不接受作爲核心問題的十進制值,當R值非浮點時,R中指令的工作正常。 – Angelo

回答

3

它看起來像你需要更好地指定breaksmin(x)max(x)之類的東西。

x <- read.table(textConnection(" 
0.0707526823 
0.4859753978 
0.0084166789 
0.0694709558 
0.0156410467 
0.3783259831 
0.8977261856 
0.7981824881 
0.2079852045 
0.9498437264 
0.9264972044 
0.1878358734 
0.0020816686 
0.0024611297 
0.4250464895 
0.0725748666 
0.0407962054 
0.8282363221 
0.8408343333 
0.7129760016 
0.2772250135 
0.3677588953 
0.4723908637 
0.9452814318")) 
#extract vector of numeric from current data frame 
x <- x$V1 
#create breaks for frequency 
#need to add a padding factor to make things equally spaced 
step <- .1 
pad <- step - ((max(x) - min(x)) %% step)/2 
breaks <- seq(min(x) - pad, max(x) + pad,by=.1) 
#alternative (only good for exact decimal increments): 
#use floor and ceiling 
breaks <- floor(min(x)*10):ceiling(max(x)*10)/10 
#create histogram 
#equally spaced breaks create frequency chart automatically 
hist(x,breaks) 
+0

謝謝,我明白了,我用x $ V1的東西搞砸了,最後一件事情(如果你有空的話)在x軸上得到垃圾箱,在Y軸上我得到密度,我怎樣才能取代密度與百分比(如在每個bin中的命中百分比) – Angelo

+2

'help(hist)'有你的答案:加'freq = TRUE'作爲'hist'的參數我正在努力使箱子大小一致 - 留調諧。 –

+0

好的,謝謝 – Angelo