2012-07-21 86 views
0

有一個data.frame什麼是矢量?

> x 

     date open high low close volume adjusted 
1 2010-01-04 24.52 24.58 23.68 23.71 24192200 23.71 
2 2010-01-05 23.75 23.90 22.75 23.30 55649900 23.30 
3 2010-01-06 23.25 23.25 22.72 22.90 41214300 22.90 
4 2010-01-07 22.90 23.05 22.40 22.65 35533600 22.65 
5 2010-01-08 22.50 22.75 22.35 22.60 28854300 22.60 
6 2010-01-11 23.50 23.68 22.28 22.60 44284600 22.60 

> is.vector(x[,1]) 
[1] FALSE 
> is.vector(x[,2]) 
[1] TRUE 
> is.vector(x[,1]) 
[1] FALSE 
> is.vector(x[,3]) 
[1] TRUE 
> is.vector(x[,4]) 
[1] TRUE 
> is.vector(x[,5]) 
[1] TRUE 
> is.vector(x[,6]) 
[1] TRUE 
> is.vector(x[,7]) 
[1] TRUE 

我想知道爲什麼is.vector(x[,1])是不是真的?

+2

請在發佈問題時遵循以下準則:http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – 2012-07-21 12:13:04

+0

也許第29-30頁的'The R Inferno'會回答你的問題。 http://www.burns-stat.com/pages/Tutor/R_inferno.pdf – 2012-07-21 16:55:46

回答

6

?is.vector

如果x是具有 沒有指定的模式的向量屬性不是名稱其他is.vector返回TRUE。否則返回FALSE。

您的第一列可能存儲爲日期類。因此,如果你得到它的屬性(使用str()),你會看到它具有一些除名稱之外的屬性。