Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to create a vector with zero values in R?
In data analysis, sometimes we need to use zeros for certain calculations, either to nullify the effect of a variable or for some other purpose based on the objective of the analysis. To deal with such type of situations, we need a zero value or a vector of zeros. There are many ways to create a vector with zeros in R. The important thing is the length of the vector.
Examples
> x1 x1 [1] 0 0 0 0 0 0 0 0 0 0 > x2 x2 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > x3 x3 [1] 0 0 0 0 0 0 0 0 0 0 > x4 x4 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > x5 x5 [1] 0 0 0 0 0 0 0 0 0 0 > x6 x6 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > x7 x7 [1] 0 0 0 0 0 0 0 0 0 0 > x8 x8 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [39] 0 0 0 0 0 0 0 0 0 0 0 0 > x9 x9 [1] 0 0 0 0 0 0 0 0 0 0 > x10 x10 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [39] 0 0 > x11 x11 [1] 0 0 0 0 0 0 0 0 0 0 > x12 x12 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Checking whether each of these objects are vector or not −
> is.vector(x1) [1] TRUE > is.vector(x2) [1] TRUE > is.vector(x3) [1] TRUE > is.vector(x4) [1] TRUE > is.vector(x5) [1] TRUE > is.vector(x6) [1] TRUE > is.vector(x7) [1] TRUE > is.vector(x8) [1] TRUE > is.vector(x9) [1] TRUE > is.vector(x10) [1] TRUE > is.vector(x11) [1] TRUE > is.vector(x12) [1] TRUE
Advertisements
