DataFrames in R –
It is used for storing data tables. It can contain multiple data types in multiple columns called fields. It is a list of vector of equal length. It is a generalized form of a matrix. It is like a table in excel sheets. It has column and row names. The name of rows are unique with no empty columns. The data stored must be numeric, character or factor type. DataFrames are heterogeneous.
Example:
Python
# creating company data frame comp.data < - data.frame( # company ids # data members comp_id = c ( 1 : 3 ), # company names comp_name = c( "Geeks" , "For" , "Geeks" ), growth = c( 16000 , 14000 , 12000 ), # company start dates # data members comp_start_date = as.Date(c( "02/05/10" , "04/04/10" , "05/03/10" )) ) print (comp.data) |
Output :
Application & Usage
- Data frames can do lot of works like fit statistics formulas.
- Processing data(Not possible with Matrix, First converting to Data Frame is mandatory).
- Transpose is possible, i.e. changing rows to columns and vice versa which is useful in Data Science.
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 vs Dataframe in R
A data structure is a particular way of organizing data in a computer so that it can be used effectively. The idea is to reduce the space and time complexities of different tasks.
The two most important data structures in R are Matrix and Dataframe, they look the same but different in nature.