How to get the type of a vector?
1
0
Entering edit mode
Peng Yu ▴ 940
@peng-yu-3586
Last seen 10.3 years ago
Hi, Please see the code below this message. 'a' is a vector, 'b' is a scalar. But their types are show the same ('numeric'). If I use 'class()', I will not be able to tell the type difference between a vector and a scalar. I am wondering if there is any other command that can tell the type difference between a vector and a scalar. Regards, Peng > a=c(1,2,3) > class(a) [1] "numeric" > b=2 > class(b) [1] "numeric"
• 551 views
ADD COMMENT
0
Entering edit mode
@sean-davis-490
Last seen 4 months ago
United States
On Thu, Aug 20, 2009 at 10:49 PM, Peng Yu <pengyu.ut@gmail.com> wrote: > Hi, > > Please see the code below this message. 'a' is a vector, 'b' is a > scalar. But their types are show the same ('numeric'). If I use > 'class()', I will not be able to tell the type difference between a > vector and a scalar. I am wondering if there is any other command that > can tell the type difference between a vector and a scalar. > > Regards, > Peng > > > a=c(1,2,3) > > class(a) > [1] "numeric" > > b=2 > > class(b) > [1] "numeric" > Both are vectors. "b" is simply a vector of length 1. See ?vector and ?length. Sean [[alternative HTML version deleted]]
ADD COMMENT

Login before adding your answer.

Traffic: 761 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6