Here we are explaining how to write an R program to create a vector and find the length and the dimension of the vector. Here we are using a built-in function dim(),length() for this finding. The function dim() helps to retrieve or set the dimension of an object. And the function length() is used to get or set the length of vectors (including lists) and factors, and of any other R object. The syntax of these functions are
dim(x) length(x)#Where x is a R object
Here x is an R object, for example, a matrix, array, or data frame.
Below are the steps used in the R program to create a vector and find the length and dimension of the vector in the R program. In this R program, we directly give the values to built-in functions. For that first, we consider the variable A in which vector value is assigned. Call the functions dim() for finding dimension and length() for finding the length of the vector. Finally, print the result.
STEP 1: Assign variable A with vector values
STEP 2: First print original vector values
STEP 3: Call the function dim() as dim(A)
STEP 4: print the result of the function
STEP 5: Call the function length() as length(A)
STEP 6: print the result of the function
A = c(1,3,5,7,9,6) print("Original vectors is:") print(A) print("Dimension of the vector is:") print(dim(A)) print("length of the vector is:") print(length(A))
 "Original vectors is:"  1 3 5 7 9 6  "Dimension of the vector is:" NULL  "length of the vector is:"  6