Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No dimensions of non-empty numeric vector in R

Tags:

r

numeric

vector

I have a problem with my numeric vector and dim() in R. I want to know the dimensions of my vector X with:

dim(X)

However, that function returns NULL.

If I type:

X

I can see that the X is not empty. Why does dim or nrow report it as "NULL"?

Part of X:
[93486] 6.343e-01 6.343e-01 6.343e-01 6.343e-01 6.343e-01 6.343e-01 6.346e-01
[93493] 6.346e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01
[93500] 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01
[93507] 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01
[93514] 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01 6.347e-01
[93521] 6.347e-01 6.347e-01 6.347e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01
[93528] 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01
[93535] 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01
[93542] 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01
[93549] 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01 6.348e-01
[93556] 6.348e-01 6.348e-01 6.349e-01 6.349e-01 6.349e-01 6.349e-01 6.349e-01
[93563] 6.349e-01 6.349e-01 6.349e-01 6.349e-01 6.349e-01 6.349e-01 6.349e-01
[93570] 6.349e-01 6.349e-01 6.349e-01 6.349e-01 6.349e-01 6.349e-01 6.349e-01

> dim(X)
NULL
> class(X)
[1] "numeric"
> nrow(pvals_vector)
NULL

Why is there no dimensions of X?

like image 933
user1261558 Avatar asked Aug 28 '13 07:08

user1261558


People also ask

How do you check a vector is empty or not in R?

If you check length(vec) , we know the length of our vector is also 0, meaning that our vector, vec , is empty. If you want to create other types of vectors that are not of type logical , you can also read the help file of vector using ? vector .

How to create an empty vector of length n in R?

Create Empty Vector using vector() The vector() function can also be used to create an empty vector in R, by default it creates logical type. vector() function takes syntax vector(mode = "logical", length = 0) so to initialize an empty vector you don't have to use any arguments.

How to initialize a vector in R?

To create a vector of specified data type and length in R we make use of function vector(). vector() function is also used to create empty vector.


1 Answers

Because it is a one-dimensional vector. It has length. Dimensions are extra attributes applied to a vector to turn it into a matrix or a higher dimensional array:

x <- 1:6
dim( x )
#NULL

length( x )
#[1] 6

dim( matrix( x , 2 , 3 ) )
#[1] 2 3
like image 85
Simon O'Hanlon Avatar answered Oct 16 '22 05:10

Simon O'Hanlon