What is the difference between a matrix and a dataframe in R?

Question

Please explain in layman terms

in progress 0
Ritika Sohal 4 years 3 Answers 1065 views Member 0

Answers ( 3 )

  1. Data frame can contain heterogeneous inputs while a matrix cannot. In a matrix, only similar data types can be stored whereas in a data frame there can be different data types like characters, integers, or other data frames. Basically Data Frame is advanced version of a Matrix where you can store various types of data input types.

  2. Matrix DataFrame
    Collection of data sets arranged in a two dimensional rectangular organisation. Stores data tables that contains multiple
    data types in multiple column called
    fields.

    It’s m*n array with similar data type. It is a list of vector of equal length. It is a
    generalized form of matrix.

    It has fixed number of rows and columns. It has variable number of rows and
    columns.

    The data stored in columns can be only of same data type. The data stored must be numeric,
    character or factor type.

    Matrix is homogeneous. DataFrames is heterogeneous.

    • Matrix:

      Collection of data sets arranged in a two dimensional rectangular organisation.
      It’s m*n array with similar data type.
      It has fixed number of rows and columns.
      The data stored in columns can be only of same data type.
      Matrix is homogeneous.

      DataFrame:

      Stores data tables that contains multiple data types in multiple column called fields.
      It is a list of vector of equal length. It is a generalized form of matrix.
      It has variable number of rows and columns.
      The data stored must be numeric, character or factor type.
      DataFrames is heterogeneous.

Leave an answer

Browse
Browse