1

There is a 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  

I want to know why is.vector(x[,1]) is not TRUE?

GSee
  • 48,880
  • 13
  • 125
  • 145
Peng Peng
  • 1,305
  • 3
  • 16
  • 20
  • 3
    Please follow these guidelines when posting questions: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Ari B. Friedman Jul 21 '12 at 12:13
  • Perhaps pages 29-30 of 'The R Inferno' will answer your question. http://www.burns-stat.com/pages/Tutor/R_inferno.pdf – Patrick Burns Jul 21 '12 at 16:55
  • Quick answer: because it’s a Date which requires an attribute that causes a numeric “vector” to lose its vectorality. – IRTFM Jun 14 '22 at 03:16

1 Answers1

8

From ?is.vector :

is.vector returns TRUE if x is a vector of the specified mode having no attributes other than names. It returns FALSE otherwise.

Your first column is likely stored as a date class. Thus if you get its attributes (using str()) you will see that it has some attributes other than just names.

Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235