How to Apply the drop() Function in R (Example Code)

In this R tutorial you’ll learn how to remove redundant dimension information using the drop function.

Constructing Example Data

x <- matrix(letters[1:5],        # Example matrix in R
            ncol = 1)
x                                # Display matrix in RStudio console
#      [,1]
# [1,] "a" 
# [2,] "b" 
# [3,] "c" 
# [4,] "d" 
# [5,] "e"

Example: Dropping Dimensions of Matrix Object Using drop() Function

drop(x)                          # Dropping dimensions
# [1] "a" "b" "c" "d" "e"

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed