R Vector

Vector

  • A Vector is a sequence of data elements of homogeneous type
  • Elements in a vector are called as components
  • Vectors can be created in many ways, few of them are:
    • by directly assigning the values to the objects
CODE/PROGRAM/EXAMPLE
x <- 1:9
	y <- c(1,4,62,1,6,3,6,3,6)
	newText <- "This is R programming"
	moreText <- c("Hi", "Adding", "Multiple", "Words")
	letseelogical <- c(TRUE, FALSE, TRUE, FALSE, TRUE, TRUE)
	COMP1 <- c(6+3i, 2+4i)

Output:

Vector example 1 in r language
Notepad

Note : c() is a generic function which combines its arguments

  • by using the following command :
    • > vector(mode= “” ,length = ‘n’ )
    • mode can have these options: numeric, integer, character, logical
    • > as.vector(x, mode = “”)

    • a <- as.vector(c(4,2,1,4,2,5,9.3), mode = “integer”)
      b <- as.vector(c(“we”, “are”, “using”, “vector”, “method”), mode = “character”)
      c <- as.vector(c(1,0,0,1,1,0,1,0), mode = “logical”)
      vector(mode = “integer”, length = 6)
      vector(mode = “logical”, length = 3)

Output:

Vector example 1 in r language
Notepad

Note: is.vector(x) will check whether the variable is a vector or not

CODE/PROGRAM/EXAMPLE
is.vector(x)
	[1]TRUE
#vector_in_r_programming #Vector_r_language #vector_in_r_language #r_language_vector

(New page will open, for Comment)

Not yet commented...