Page 213 - Data Science class 11
P. 213
6.6.1 types of Vectors
There are two types of vectors:
• Atomic vectors, of which there are six types:
✶ logical
✶ integer
✶ double (for floating point numbers with double precision)
✶ complex
✶ character
✶ raw
Integer and double vectors are collectively known as numeric vectors.
• Lists, which are sometimes called recursive vectors because lists can contain other lists.
There are six basic vectors:
When a person writes just one value in R, it becomes a vector of length one and belongs to one of the
above-stated vector types. Such a vector is called a single-element vector.
6.6.2 creating a Vector
When you want to create a vector with more than one element, you should use the c() function, which means
combining the elements into a vector.
Enter the following code snippet:
# Create a vector.
apple <- c(‘red’,’green’,"yellow")
print(apple)
# Get the class of the vector.
print(class(apple))
When you execute the above code it produces the following result:
A vector is created using the function c() (to concatenate), as follows:
# Store your friends’age in a numeric vector
friend_ages <- c(27, 25, 29, 26) # Create
friend_ages # Print
[1] 27 25 29 26
Programming with R 211

