The following few R statements try to point out some differences between data frames and matrices. The script creates a data frame (df) and a matrix (mx) both of which have the same dimensions (3 columns times 2 rows) and the same data.
Then, the objects' attributes are determined with the respective function attributes(). It turns out that the data frame has the three attributes names, class and row.names while the matrix has only the single attribute dim.
Finally, applying length() on the objects returns 3 for the data frame, reflecting the three columns, and 6 for the matrix, reflecting the number of elements in the matrix.
Because a data frame might contain different data types but a matrix is constrained to a single data type, the conversion from a data frame to a matrix coerces all values of the data frame to the same data type in the matrix.