R Data Frames

A Data Frame is where data of different types are stored in a table form i.e. rows and columns. The name of rows should be unique. The column name can never be empty. Even if Data Frame has data of different types, but the datatype of each column should have similar data type.

We will cover the following topics:

  • Create a Data Frame in R
  • Access Data Frame Items
  • Count the Rows and Columns in a Data Frame
  • Length of a Data Frame
  • Summarize the Data in the Data Frame

Create a Data Frame in R

To create a Data Frame in the R programming language, use the data.frame() method. Let us see an example:

Output

Access Data Frame Items

To access data frame items in the R programming language, use any of the following:

  • Single Bracket
  • Double Brackets
  • Dollar sign

Let us see the examples of all the three ways mentioned above, beginning with single bracket

Access items using a Single Bracket

Let us see an example to access data frame items using [ ]. Under the bracket, mention the column number of the column you want to access:

Output

Access items using Double Brackets

Let us see an example to access data frame items using [[ ]]. Under the double brackets, mention the column name of the column you want to access:

Output

Access items using $

Let us see an example to access data frame items in the R programming language using $:

Output

Count the Rows and Columns in a Data Frame

The dim() function is used in the R programming language to count the rows and columns in a Data Frame. Let us see an example:

Output

Length of a Data Frame

To get the length of a Data Frame, use the length() function in the R programming language. The length gets the count of columns of a Data Frame. Let us see an example:

Output

Summarize the Data in the Data Frame

The summary() function is used to summarize the data in the R Data Frame. The summary is displayed in the form of mean, median, minimum value, maximum value, etc. Let us see an example:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

R Matrices
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading