Vectors:
--------------------------------------------------------------------------------------------------------------------------
there are six types in the Vectors:
--------------------------------------------------------------------------------------------------------------------------
Logical -- when a value is true or false, then it shoes the class of the value:
for example:
> vectorone <- TRUE
assigning TRUE to the vectorone variable
> print(vectorone)
printing thevariable
Output
[1] TRUE
> print(class(vectorone))
printing the class of the vectorone
Output:
[1] "logical"
--------------------------------------------------------------------------------------------------------------------------
> vectorone <- 26.5
assigning the numerical value for variable vectorone
> print(vectorone)
printing the vectorone
Output
[1] 26.5
> print(class(vectorone))
printing the class of the vector
Output:
[1] "numeric"
> vectorone <- 23
assigning the value for the vectorone
> print(vectorone)
printing the value
Output:
[1] 23
> print(class(vectorone))
printing the class of the variable
Output
[1] "numeric"
-------------------------------------------------------------------------------------------------------------------------
> vectortwo<-"your name"
Assigning the value for vectortwo
> print(vectortwo)
printing the value of the variable
Output
[1] "your name"
printing the class of the variable
Output
> print(class(vectortwo))
[1] "character"
--------------------------------------------------------------------------------------------------------------------------
vector3 <- 1L
Assigning the value for the vector3
printing the vector3
> print(vector3)
Output:
[1] 1
printing the class of the vector3
> print(class(vector3))
Output:
[1] "integer"
--------------------------------------------------------------------------------------------------------------------------
> vector4 <- 1+2i
assigning the complex value for the vector4
> print(vector4)
printing the vector4
Output
[1] 1+2i
printing the class of the vector3
> print(class(vector4))
Output
[1] "complex"
--------------------------------------------------------------------------------------------------------------------------
To create vector more than one value , we use c() it is a combiner function then the syntax ill be in the following format,
> vector5 <- c("firstname",2L,23.6,2+3i,TRUE)
assigning multiple values to the vector5
> print(vector5)
printing vector5
Output
[1] "firstname" "2" "23.6" "2+3i" "TRUE"
Printing the class of the vector5:
Output
> print(class(vector5))
[1] "character"
No comments:
Post a Comment