R Data Frame - Javatpoint
R Data Frame - Javatpoint
Home Python Java JavaScript HTML SQL PHP C#
← prev next →
R Data Frame
A data frame is used to store data table and the vectors which are present in the form of a
list in a data frame, are of equal length.
In a simple way, it is a list of equal length vectors. A matrix can contain one type of data, but
a data frame can contain different data types such as numeric, character, factor, etc.
ADVERTISEMENT
The columns name should be non-empty.
The data which is stored in a data frame can be a factor, numeric, or character
type.
Example
ADVERTISEMENT
Output
employee_idemployee_namesalstarting_date
1 1 Shubham623.30 2012-01-01
2 2 Arpita915.20 2013-09-23
3 3 Nishka611.00 2014-11-15
4 4 Gunjan729.00 2014-05-11
5 5 Sumit843.25 2015-03-27
Output
1. We can extract the specific columns from a data frame using the column name.
2. We can extract the specific rows also from a data frame.
3. We can extract the specific rows corresponding to specific columns.
Let's see an example of each one to understand how data is extracted from the data frame
with the help these ways.
Example
Output
emp.data.employee_idemp.data.sal
1 1 623.30
2 2 515.20
3 3 611.00
4 4 729.00
5 5 843.25
Output
employee_id starting_date
2 2 2013-09-23
3 3 2014-11-15
We can
1. Add a column by adding a column vector with the help of a new column name using cbind()
function.
2. Add rows by adding new rows in the same structure as the existing data frame and using
rbind() function
3. Delete the columns by assigning a NULL value to them.
4. Delete the rows by re-assignment to them.
Let's see an example to understand how rbind() function works and how the modification is
done in our data frame.
Output
Output
employee_idemployee_namesalstarting_date
1 1 Shubham623.30 2012-01-01
2 2 Arpita515.20 2013-09-23
3 3 Nishka611.00 2014-11-15
4 4 Gunjan729.00 2014-05-11
5 5 Sumit843.25 2015-03-27
employee_idemployee_namesalstarting_date
2 2 Arpita515.20 2013-09-23
3 3 Nishka611.00 2014-11-15
4 4 Gunjan729.00 2014-05-11
5 5 Sumit843.25 2015-03-27
employee_idemployee_namesal
1 1 Shubham623.30
2 2 Arpita515.20
3 3 Nishka611.00
4 4 Gunjan729.00
5 5 Sumit843.25
Summary of data in Data Frames
In some cases, it is required to find the statistical summary and nature of the data in the
data frame. R provides the summary() function to extract the statistical summary and
nature of the data. This function takes the data frame as a parameter and returns the
statistical information of the data. Let?s see an example to understand how this function is
used in R:
Example
Output
employee_idemployee_namesalstarting_date
1 1 Shubham623.30 2012-01-01
2 2 Arpita515.20 2013-09-23
3 3 Nishka611.00 2014-11-15
4 4 Gunjan729.00 2014-05-11
5 5 Sumit843.25 2015-03-27
employee_idemployee_namesalstarting_date
Min. :1 Length:5 Min. :515.2 Min. :2012-01-01
1st Qu.:2 Class :character 1st Qu.:611.0 1st Qu.:2013-09-23
Median :3 Mode :character Median :623.3 Median :2014-05-11
Mean :3 Mean :664.4 Mean :2014-01-14
3rd Qu.:4 3rd Qu.:729.0 3rd Qu.:2014-11-15
Max. :5 Max. :843.2 Max. :2015-03-27
← prev next →
Python Java
Javascript HTML
Database PHP