Output: [1] TRUE TRUE TRUE FALSE
7.w < −c(1, 4)%in%c(1, 2, 3)
Output: [1] TRUE FALSE
Character Vector:A character vector is a group of strings. Strings in R can
contain alphabets, numbers, and symbols. In R, there are two different ways
to create a character vector either by typing string between double quotes(””)
or single quotes(”).
Examples
1. ch < −”hello, world!”
Output:1] ”hello, world!”
2. t < −c(”Sun”, ”Mon”, ”T ue”, ”W ed”, ”T hurs”, ”F ri”, ”Sat”)
Output: [1] ”Sun” ”Mon” ”Tue” ”Wed” ”Thurs” ”Fri” ”Sat”
Complex Vector: Complex vectors are vectors used to store numbers with an
imaginary component. Complex vectors are vectors of complex values.
Examples:
1. x = 4 + 3i
Output: [1] 4+3i
2. y < −2 − 2i
Output: [1] 2-2i
Raw Vector: Raw vectors basically store raw binary data that is represented
in the hexadecimal form. To save and work with data at the byte level in R,
use the raw data type.Raw vectors can be created using the raw() function.
Examples
1. x < −raw(12)
Output:
[1] 00 00 00 00 00 00 00 00 00 00 00 00
2.Convert character to raw
raw variable < −charT oRaw(”Welcome to Programiz”)
print(raw variable)
Output:
[1] 57 65 6c 63 6f 6d 65 20 74 6f 20 50 72 6f 67 72 61 6d 69 7a
1.8.2 Subsetting vectors
Subsetting a vector means accessing some specific entries or a subset of the
vector. We can access the elements of a vector with the help of vector indexing.
Indexing denotes the position where the value in a vector is stored. We perform
indexing by specifying an integer value in square braces [ ] next to our vector.
Examples:
1. x < −2 : 10
Output:[1] 2 3 4 5 6 7 8 9 10
x[4]
Output: [1] 5
x[c(2, 4, 8)]
Output: [1] 3 5 9
x[4 : 7]
Output: [1] 5 6 7 8
x[−4]
Output: [1] 2 3 4 6 7 8 9 10
x[c(T RUE, F ALSE, F ALSE, F ALSE, T RUE, F ALSE, T RUE, T RUE)]
Output: [1] 2 6 8 9 10
2.myvector[c(2, 5, 8)]
Output: [1] FALSE TRUE TRUE
w[2]
Output: [1] FALSE
3. t[5 : 7]
Output: [1] ”Thurs” ”Fri” ”Sat”