2016-02-25 95 views
-1

我對R很新,所以請耐心等待。如何計算R中數據集的平均向量?

testdata <- read.table("testdata.txt", header = TRUE) 

它創建了15個OBS數據:

的.txt文件給出的測試數據...

 
Num height weight class 
1  72.1  147.5 1 
2  75.2  125.4 1 
3  60.3  102.3 2 
4  62.4  98.2  2 
5  50.5  74.1  3 

我通過文件讀入到R上。的4個變量。我可以每列分配給一個對象,像這樣:

numCol <- testdata$Num 
heightCol <- testdata$height 
weightCol <- testdata$weight 
classCol <- testdata$class 

然後,例如,heightCol給我

heightCol 
> 72.1 75.2 60.3 62.4 50.5 

我需要做的就是把每類並找到平均值向量,標準偏差,散點圖和平行座標。

如果有人能向我解釋如何找到,只是意味着什麼,我相信我可以找出其餘的。

+0

'集合體(高度〜類,數據= TESTDATA,平均)'? – JasonAizkalns

回答

0
colMeans(testdata) 

apply(testdata, 2, mean) 

更多細節請參閱幫助文檔

?colMeans 
?apply 
+0

不會做OP正在尋找的東西。 – 2016-02-25 19:37:40

相關問題