- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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<-integer(10) > x1 [1] 0 0 0 0 0 0 0 0 0 0 > x2<-integer(20) > x2 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > x3<-numeric(10) > x3 [1] 0 0 0 0 0 0 0 0 0 0 > x4<-numeric(20) > x4 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > x5<-replicate(10,0) > x5 [1] 0 0 0 0 0 0 0 0 0 0 > x6<-replicate(100,0) > 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<-(1:10)*0 > x7 [1] 0 0 0 0 0 0 0 0 0 0 > x8<-(1:50)*0 > 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<-rep(0,10) > x9 [1] 0 0 0 0 0 0 0 0 0 0 > x10<-rep(0,40) > 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<-rep(0L,10) > x11 [1] 0 0 0 0 0 0 0 0 0 0 > x12<-rep(0L,100) > 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
- Related Articles
- How to create a vector with zero values in R Program?
- How to create a vector with repeated values in R?
- How to create sets using vector values in R?
- How to create a random vector of integers with increasing values only in R?
- How to replace values in a vector with values in the same vector in R?
- Create a number vector in R with initial values as zero by defining the maximum digits for each value.
- How to add zero before a vector in R?
- How to check matrix values equality with a vector values in R?
- How to create a matrix using vector of string values in R?
- How to create a character vector from data frame values in R?
- How to create a date vector with randomization in R?
- How to create a random vector for a range of values in R?
- How to create a vector of data frame values by rows in R?
- How to create vector in R with a sequence of numbers?
- How to match the names of a vector in sequence with string vector values in another vector having same values in R?

Advertisements