Loading, please wait...

A to Z Full Forms and Acronyms

Explain Data Frames in the R programming language | R Tutorial

Jan 26, 2022 #RLanguage #Programming, 1830 Views
In this article, you will learn about the Data Frames in the R programming language along withCharacteristics of Data FrameSteps to create the Data FrameStructure of Data FrameHow to extract data from Data Frame

Explain Data Frames in the R programming language | R Tutorial

In this article, you will learn about the Data Frames in the R programming language along with

  • Characteristics of Data Frame
  • Steps to create the Data Frame
  • Structure of Data Frame
  • How to extract data from Data Frame

What is a Data Frame?

Data Frame is a data structure in the R programming language. It is used to store the data in the tabular form in two-dimensional. It falls under the special category of list data structure. It is always of equal length. R language has in-built function data.frame(). We create the data frames and assign the data elements using the in-built function data.frame(). The user can also modify the name of the data frame and retrieve data elements from the data frames. R language structured the column name as the component name and structure the row name as the component value. It is used mostly in developing machine learning models. 

The characteristics of the data frame are as follow:

  • The most highlighted point is that the number of items in each column should be the same. 
  • It is important to give the name to the column. 
  • The name of every row should be unique. 

Steps to create the Data Frame:

1. Create the Data Frame of the entrance result.

Example:

entrance_result = dataframe(Serial_no = c(101: 108), Name = c(James, Jonny, Ram, Mohan, Viju, Harry, Chuck, Joe), Marks = c(300, 410, 210, 650, 430, 560, 110, 290), stringsAsFactors = FALSE) 

print(entrance_result)

When we run the above code, it will give me the following output:

      Serial_no Name Marks

1 101 James 300

2 102 Jonny 410

3 103 Ram 210

4 104 Mohan 650

5 105 Viju 430

6 106 Harry 560

7 107 Chuck 110

8 108 Joe 290

 

2. Now, add the code written below. 

Str(entrance_result)

When we run the code, we will get the following output:

‘data.frame’: 8 observations of 3 variables:

$ Serial_no = num 101 102 103 104 105 106 107 108

$ Name = char “James” “Jonny” “Ram” “Mohan” “Viju” “Harry” “Chuck” “Joe”

$ Marks = num 300 410 210 650 430 560 110 290

3. Now, use the summary function to get a precise understanding of the provided data. It will fetch the min, max, mean, median, and quartile from the data. It will give the class, mode, and length of the char type variable. 

Structure of the Data Frame 

R programming language gives us the advantage through which we can find the structure of the data frame by using the str() function. It is exactly the same thing we did in step 2 under the subtopic “Steps to create the data frame”.

Extract the data from the data frame

Let’s consider the above data frame to understand this. If you want to extract only the name from the data frame. We can do so by the dollar($) symbol. 

name_only = entrance_result$Name

print(name_only)

When we run the following code, it will give you the following output:

[1] “James” “Jonny” “Ram” “Mohan” “Viju” “Harry” “Chuck” “Joe”

It breaks the code from between to put the dollar sign. 

A to Z Full Forms and Acronyms