The c() function can also combine two or more vectors and add elements to vectors. Their type is double while their class is numeric. The numeric class stores values as double-precision floating-point numbers.
This is because of the way numeric-class stores a value. Note: The typeof() function returns “double” for numeric values. We can use the typeof() function to find the type of a vector. Character VectorsĬode: > char_vec char_vec 5. Vectors containing logical values of TRUE or FALSE.Ĭode: > log_vec log_vec 4. Integer VectorsĬode: > int_vec int_vec 3.
Numeric VectorsĬode: > num_vec num_vec 2. To create a vector, we use the c() function:Īnother way to create a vector is the assign() function.Ĭode: > assign('vec2',c(6,7,8,9,10)) #creates a vector named vec2Īn easy way to make integer vectors is to use the : operator.Ī vector can be of different types depending on the elements it contains. There are numerous ways to create an R vector: 1. Keeping you updated with latest technology trends, Join TechVidvan on Telegram How to create vector in R?