Accenture Interview Questions | Data Frame vs Data Table
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 3 )
DataTable is a an extended version of DataFrame and has several additional features
than those provided by a DataFrame. Some of the advantages of using DataTable are as folllows
1) It is much faster at loading data compared to a dataframe.
2) Reading and writing files is much faster with data.table than with read.csv()
3) Inbuilt features like automatic indexing makes processing large data sets faster.
4) It is faster than the dplyr packages used for data manipulation.
A data.frame is a list of vectors of the same length, with a few extra attributes such as column names.
data.table:
1. Allow columns to be assigned or modified by reference.
2. Allow the data table’s to be quickly aggregated or summarized using keys.
3.Create a framework for syntax which is easier to read, leading to less repetition and fewer mistake
Data frames are lists of vectors of equal length while data tables (data.table) is an inheritance of data frames. Therefore data tables are data frames but data frames are not necessarily data tables. The data tables package and function were written to enhance the speed of indexing, ordered joins, assignment, grouping and listing columns etc.
Its objectives:
Allow columns to be assigned or modified by reference.
Allow data table’s to be quickly aggregated or summarized using keys.
Create a framework for syntax which is easier to read, leading to less repetition and fewer mistakes.
#creating a dummy data table
DT DT[Code == “C”, mean(Capacity), State]
I asked data table to filter the rows whose code is C. Then I asked it to calculate the mean capacity of the rows which have code C for every state separately.