The “as.vector” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Converts an object to a vector.

  • General Class: Data Manipulation

  • Required Argument(s):

    • x: An R object to be converted to a vector.

  • Notable Optional Arguments:

    • mode: The mode of the resulting vector. By default, the mode is determined from the highest type of the components in x.

    • ...: Additional arguments for methods.

  • Example:

  • # Example data for using the as.vector function
    matrix_example <- matrix(1:6, nrow = 2, ncol = 3)

    # Use as.vector to convert a matrix to a vector
    vector_result <- as.vector(matrix_example)

    # Display the result
    print(vector_result)

  • In this example, the as.vector function is used to convert a matrix (matrix_example) to a vector (vector_result). The as.vector function is commonly used to simplify the structure of an object and convert it to a one-dimensional vector.

Previous
Previous

The “as.matrix” Function in R

Next
Next

The “unsplit” Function in R