Difference between revisions of "R/C2/Indexing-and-Slicing-Data-Frames/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 5: Line 5:
 
'''Keywords''': R, RStudio, data frames, indexing, slicing, working directory, video tutorial.
 
'''Keywords''': R, RStudio, data frames, indexing, slicing, working directory, video tutorial.
  
{| style="border-spacing:0;width:18.785cm;"
+
 
|-
+
 
| align=center style="background-color:#ffffff;border-top:1.25pt solid #000001;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''Visual Cue'''
+
{|border=1
| align=center style="background-color:#ffffff;border:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''Narration'''
+
||'''Visual Cue'''
 +
||'''Narration'''
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
||Show slide
  
 
Opening slide
 
Opening slide
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Welcome to the spoken tutorial on </span><span style="background-color:#ffffff;">'''Indexing and Slicing Data Frames'''</span><span style="background-color:#ffffff;">. </span>
+
||Welcome to the spoken tutorial on '''Indexing and Slicing Data Frames'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
||Show slide
  
 
Learning Objectives
 
Learning Objectives
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In this tutorial, we will learn how to:
+
 
* <div style="margin-left:1.947cm;margin-right:0cm;">Extract '''rows''' or '''columns''' from a '''data '''frame</div>
+
||In this tutorial, we will learn how to:
* <div style="margin-left:1.947cm;margin-right:0cm;">Create a '''subset''' from a''' data frame'''</div>
+
 
* <div style="margin-left:1.947cm;margin-right:0cm;">Retrieve '''data '''using double square brackets</div>
+
* Extract '''rows''' or '''columns''' from a '''data '''frame
 +
* Create a '''subset''' from a''' data frame'''
 +
* Retrieve '''data '''using double square brackets
 +
 
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
||Show slide
  
 
Pre-requisites
 
Pre-requisites
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | To understand this tutorial, you should have knowledge about  
+
 
* <div style="margin-left:1.947cm;margin-right:0cm;">'''Data frames''' in''' R''' </div>
+
 
* <div style="margin-left:1.947cm;margin-right:0cm;">'''R''' '''script '''in '''RStudio '''and</div>
+
||To understand this tutorial, you should have knowledge about  
* <div style="margin-left:1.947cm;margin-right:0cm;">How to set '''Working directory''' in''' RStudio'''</div>
+
 
 +
* '''Data frames''' in''' R'''  
 +
* '''R''' '''script '''in '''RStudio '''and
 +
* How to set '''Working directory''' in''' RStudio'''
  
 
If not, please locate the relevant tutorials on '''R''' on this website.
 
If not, please locate the relevant tutorials on '''R''' on this website.
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
||Show slide
  
 
System Specifications
 
System Specifications
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | This tutorial is recorded on
+
||This tutorial is recorded on
* <div style="margin-left:1.947cm;margin-right:0cm;">'''Ubuntu Linux '''OS version''' 16.04'''</div>
+
 
* <div style="margin-left:1.947cm;margin-right:0cm;">'''R '''version''' 3.2.3'''</div>
+
* '''Ubuntu Linux '''OS version''' 16.04'''
* <div style="margin-left:1.947cm;margin-right:0cm;">'''RStudio''' version''' 1.1.456'''</div>
+
* '''R '''version''' 3.2.3'''
 +
* '''RStudio''' version''' 1.1.456'''
  
 
Install '''R''' version '''3.2.0''' or higher.
 
Install '''R''' version '''3.2.0''' or higher.
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide  
+
||Show slide  
 +
 
  
 
Download Files  
 
Download Files  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | For this tutorial, we will use the '''data frame CaptaincyData.csv''' and a '''script '''file '''mydataframe.R'''.  
+
||For this tutorial, we will use the '''data frame CaptaincyData.csv''' and a '''script '''file '''mydataframe.R'''.  
 +
 
  
 
Download these files from the '''Code files''' link of this tutorial.
 
Download these files from the '''Code files''' link of this tutorial.
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [Computer screen]
+
||[Computer screen]
  
 
Highlight '''CaptaincyData.csv '''and''' mydataframe.R '''in the folder '''myProject'''
 
Highlight '''CaptaincyData.csv '''and''' mydataframe.R '''in the folder '''myProject'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | I have downloaded and moved these files to the folder '''myProject''' on my '''Desktop'''.  
+
||I have downloaded and moved these files to the folder '''myProject''' on my '''Desktop'''.  
 +
 
  
 
I have also set this folder as my '''Working Directory.'''  
 
I have also set this folder as my '''Working Directory.'''  
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Let us switch to&nbsp;'''RStudio'''.
+
||Let us switch to '''Rstudio'''.
 +
 
 +
 
 +
 
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Point to script '''mydataframe.R.'''
+
||Point to script '''mydataframe.R.'''
  
 
Click '''mydataframe.R''' in '''RStudio'''
 
Click '''mydataframe.R''' in '''RStudio'''
 +
  
 
Point to''' mydataframe.R''' in '''Rstudio.'''
 
Point to''' mydataframe.R''' in '''Rstudio.'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Let us open the '''script mydataframe.R''' in '''RStudio.'''
+
||Let us open the '''script mydataframe.R''' in '''RStudio.'''
  
 
For this, click on the '''script mydataframe.R'''  
 
For this, click on the '''script mydataframe.R'''  
 +
  
 
'''Script mydataframe.R '''opens in''' Rstudio.'''
 
'''Script mydataframe.R '''opens in''' Rstudio.'''
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
 
'''captaincy <- read.csv("CaptaincyData.csv")'''
 
'''captaincy <- read.csv("CaptaincyData.csv")'''
  
 
'''View(captaincy)'''
 
'''View(captaincy)'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Here, we have declared a''' variable captaincy''' to store and read '''CaptaincyData.csv'''.
+
||Here, we have declared a''' variable captaincy''' to store and read '''CaptaincyData.csv'''.
 +
 
  
 
Also, '''View function''' is being used to see the contents of the file.
 
Also, '''View function''' is being used to see the contents of the file.
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight''' <-''' symbol in the '''Source''' window
+
||Highlight''' <-''' symbol in the '''Source''' window
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Remember, you may also use '''equal''' to sign in place of '''less than''' symbol followed by '''hyphen'''.  
+
||Remember, you may also use '''equal''' to sign in place of '''less than''' symbol followed by '''hyphen'''.
 +
 
 +
 
 +
However, we recommend '''less than''' symbol followed by '''hyphen'''.
  
However, we recommend <span style="color:#434343;">'''l</span>ess than''' symbol followed by '''hyphen'''.
 
  
 
For this, there is a shortcut in '''RStudio'''.  
 
For this, there is a shortcut in '''RStudio'''.  
 +
  
 
Suppose we want to assign a value of 2 to a variable named '''testvar'''.  
 
Suppose we want to assign a value of 2 to a variable named '''testvar'''.  
 +
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
 
'''Alt '''+ '''-'''
 
'''Alt '''+ '''-'''
  
 
'''testvar <- 2'''
 
'''testvar <- 2'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Console''' window, type '''testvar''' and then press  
+
||In the '''Console''' window, type '''testvar''' and then press  
  
 
'''Alt '''and '''-'''('''hyphen''')''' '''keys simultaneously.
 
'''Alt '''and '''-'''('''hyphen''')''' '''keys simultaneously.
  
 
Then type 2 and press '''Enter'''.  
 
Then type 2 and press '''Enter'''.  
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight '''mydataframe.R''' in the '''Source''' window  
+
||Highlight '''mydataframe.R''' in the '''Source''' window  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Let us get back to the '''Source''' window.  
+
||Let us get back to the '''Source''' window.  
  
 
Run the '''script''' '''mydataframe.R''' by clicking on the '''Source''' button.  
 
Run the '''script''' '''mydataframe.R''' by clicking on the '''Source''' button.  
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
 
Highlight third row of '''captaincy '''
 
Highlight third row of '''captaincy '''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let us extract the contents of the third row of the '''captaincy data frame'''.  
+
||Now let us extract the contents of the third row of the '''captaincy data frame'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on the '''script''' '''mydataframe.R'''
+
||Click on the '''script''' '''mydataframe.R'''
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
 +
 
  
 
'''captaincy[3,]'''
 
'''captaincy[3,]'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, type '''captaincy '''
+
||In the '''Source '''window, type '''captaincy '''
 +
 
  
 
Type '''capt''' and press '''Enter '''to make the variable '''captaincy '''autocomplete. Now''' '''within square brackets 3 followed by '''comma. '''And press '''Enter'''.  
 
Type '''capt''' and press '''Enter '''to make the variable '''captaincy '''autocomplete. Now''' '''within square brackets 3 followed by '''comma. '''And press '''Enter'''.  
 +
  
 
Press '''Enter '''key''' '''at the end of every command.  
 
Press '''Enter '''key''' '''at the end of every command.  
  
 
Remember one of the most important features of '''RStudio '''include intelligent auto-completion of function names, packages, and R objects.  
 
Remember one of the most important features of '''RStudio '''include intelligent auto-completion of function names, packages, and R objects.  
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight comma in the '''Source '''window
+
||Highlight comma in the '''Source '''window
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">We use a </span><span style="background-color:#ffffff;">'''comma'''</span><span style="background-color:#ffffff;"> within square brackets when we wish to extract a </span><span style="background-color:#ffffff;">'''row'''</span><span style="background-color:#ffffff;">.</span>
+
||We use a '''comma''' within square brackets when we wish to extract a '''row'''.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
+
||Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Save the '''script '''and execute the current line by pressing '''Ctrl+Enter''' keys.
+
||Save the '''script '''and execute the current line by pressing '''Ctrl+Enter''' keys.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the output in the '''Console '''window
+
||Highlight the output in the '''Console '''window
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The third row of the '''captaincy data frame''' is seen in the '''Console''' window.  
+
||The third row of the '''captaincy data frame''' is seen in the '''Console''' window.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight '''comma '''in '''captaincy[3,]'''
+
||Highlight '''comma '''in '''captaincy[3,]'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now, let us run the same '''command''' without a '''comma'''.  
+
||Now, let us run the same '''command''' without a '''comma'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
 
'''captaincy[3]'''
 
'''captaincy[3]'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, type '''captaincy '''then''' '''within square brackets 3'''. '''
+
||In the '''Source '''window, type '''captaincy '''then''' '''within square brackets 3'''. '''
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
+
||Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Save the '''script '''and run this line only, as shown earlier.
+
||Save the '''script '''and run this line only, as shown earlier.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the output in the '''Console '''window
+
||Highlight the output in the '''Console '''window
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The contents of the third '''column''' of the '''data frame, '''are displayed on the '''Console '''window.
+
||The contents of the third '''column''' of the '''data frame, '''are displayed on the '''Console '''window.
 +
 
 
|-
 
|-
| style="border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
| |  
| style="border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | So, to extract a '''column''', we shouldn’t use a '''comma''' within the square brackets.
+
| | So, to extract a '''column''', we shouldn’t use a '''comma''' within the square brackets.
  
 
When we extract '''data''' using row number or column number, it is known as numeric indexing.  
 
When we extract '''data''' using row number or column number, it is known as numeric indexing.  
 +
 
|-
 
|-
| style="border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
| |  
| style="border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, click on the '''captaincy data frame'''.  
+
| | In the '''Source '''window, click on the '''captaincy data frame'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
 
Highlight second and third rows of '''captaincy'''
 
Highlight second and third rows of '''captaincy'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Let us now extract the contents of second and third </span><span style="background-color:#ffffff;">'''rows'''</span><span style="background-color:#ffffff;"> of the </span>'''captaincy''' '''data frame'''.
+
||Let us now extract the contents of second and third '''rows''' of the '''captaincy''' '''data frame'''.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
  
Line 170: Line 218:
  
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">To retrieve more than one </span><span style="background-color:#ffffff;">'''row'''</span><span style="background-color:#ffffff;">, we use a numeric </span><span style="background-color:#ffffff;">'''index vector'''</span><span style="background-color:#ffffff;">. Click on the </span><span style="background-color:#ffffff;">'''script mydataframe.R'''</span>
 
  
<span style="background-color:#ffffff;">In the </span><span style="background-color:#ffffff;">'''Source'''</span><span style="background-color:#ffffff;"> window, type the following command and press </span><span style="background-color:#ffffff;">'''Enter'''</span><span style="background-color:#ffffff;">.</span>
+
||To retrieve more than one '''row''', we use a numeric '''index vector'''. Click on the '''script mydataframe.R'''
 +
 
 +
In the '''Source''' window, type the following command and press '''Enter'''.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the '''c() function'''
+
||Highlight the '''c() function'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">'''c'''</span><span style="background-color:#ffffff;"> </span><span style="background-color:#ffffff;">'''function '''</span><span style="background-color:#ffffff;">is being used to concatenate the second and third </span><span style="background-color:#ffffff;">'''rows'''</span><span style="background-color:#ffffff;">.</span>
+
||'''c''' '''function '''is being used to concatenate the second and third '''rows'''.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
+
||Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Save the''' script''' and execute the current line.  
+
||Save the''' script''' and execute the current line.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the output in the '''Console '''window
+
||Highlight the output in the '''Console '''window
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The second and third '''rows''' of '''captaincy data frame''' are seen in the '''Console''' window.  
+
||The second and third '''rows''' of '''captaincy data frame''' are seen in the '''Console''' window.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, click on the '''captaincy data frame'''.  
+
| | In the '''Source '''window, click on the '''captaincy data frame'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now, we’ll find who has played 25 matches from the '''played''' column of '''captaincy data frame'''.  
+
||Now, we’ll find who has played 25 matches from the '''played''' column of '''captaincy data frame'''.  
  
 
Extracting this type of information is known as logical indexing.  
 
Extracting this type of information is known as logical indexing.  
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Click on the </span><span style="background-color:#ffffff;">'''script mydataframe.R'''</span>
+
||Click on the '''script mydataframe.R'''
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
  
 
'''captaincy[captaincy$played==25,]'''
 
'''captaincy[captaincy$played==25,]'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, type '''captaincy'''
+
||In the '''Source '''window, type '''captaincy'''
  
 
Within square brackets '''captaincy '''dollar sign '''played '''equal to equal to 25 '''comma. '''Press '''Enter'''.
 
Within square brackets '''captaincy '''dollar sign '''played '''equal to equal to 25 '''comma. '''Press '''Enter'''.
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight '''dollar '''sign
+
||Highlight '''dollar '''sign
  
  
 
Highlight two equal to signs  
 
Highlight two equal to signs  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Remember, '''dollar''' sign allows you to extract '''elements''' by name.<span style="background-color:#ffffff;color:#242729;"> </span>
+
||Remember, '''dollar''' sign allows you to extract '''elements''' by name.  
  
 
Please note that there is no space between the two equal to signs.  
 
Please note that there is no space between the two equal to signs.  
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
+
||Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Save the '''script''' and execute the current line.  
+
||Save the '''script''' and execute the current line.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the output in the '''Console '''window  
+
||Highlight the output in the '''Console '''window  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The details of '''captain Dravid '''are shown in the '''Console''' window.
+
||The details of '''captain Dravid '''are shown in the '''Console''' window.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | click on the '''captaincy data frame''' in '''Source''' window.
+
||click on the '''captaincy data frame''' in '''Source''' window.
| style="border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, click on the '''captaincy data frame'''.  
+
| | In the '''Source '''window, click on the '''captaincy data frame'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let us learn how to get the values of any particular '''attribute''' for all the players.
+
||Now let us learn how to get the values of any particular '''attribute''' for all the players.
  
 
We will fetch the '''names '''of all the captains.
 
We will fetch the '''names '''of all the captains.
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
 
Highlight first column of '''captaincy '''
 
Highlight first column of '''captaincy '''
  
 
'''captaincy[1]'''
 
'''captaincy[1]'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | For this, we need to know the values in the first '''column'''.  
+
||For this, we need to know the values in the first '''column'''.  
  
<span style="background-color:#ffffff;">Click on the </span><span style="background-color:#ffffff;">'''script mydataframe.R'''</span>
+
Click on the '''script mydataframe.R'''
  
 
In the '''Source '''window, type '''captaincy '''and''' '''within square brackets '''1'''.
 
In the '''Source '''window, type '''captaincy '''and''' '''within square brackets '''1'''.
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight 1 in square brackets  
+
||Highlight 1 in square brackets  
 +
 
 +
 
 +
 
 +
||Please note that I have not used a '''comma''' inside the square brackets.
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Please note that I have not used a '''comma''' inside the square brackets.
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
+
||Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Save the '''script''' and execute the current line.  
+
||Save the '''script''' and execute the current line.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the output in the '''Console '''window  
+
||Highlight the output in the '''Console '''window  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The '''names''' of the captains are seen in the '''Console''' window.  
+
||The '''names''' of the captains are seen in the '''Console''' window.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Usually we use column '''names''' instead of column numbers.
+
||Usually we use column '''names''' instead of column numbers.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
 
'''captaincy["names"]'''
 
'''captaincy["names"]'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | To know the names of the captains, type '''captaincy. '''
+
||To know the names of the captains, type '''captaincy. '''
  
 
Within square brackets inside double quotes '''names'''
 
Within square brackets inside double quotes '''names'''
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
+
||Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Save the '''script''' and execute the current line.  
+
||Save the '''script''' and execute the current line.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Point to the names in the '''Console '''window.
+
||Point to the names in the '''Console '''window.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Names of the captains are shown in the '''Console''' window.  
+
||Names of the captains are shown in the '''Console''' window.  
  
 
Extracting '''data''' by column names is known as name indexing.  
 
Extracting '''data''' by column names is known as name indexing.  
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the broom icon in the''' Console '''window
+
||Highlight the broom icon in the''' Console '''window
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Clear the '''Console''' window by clicking on the broom icon.  
+
||Clear the '''Console''' window by clicking on the broom icon.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, click on the '''captaincy data frame'''.  
+
| | In the '''Source '''window, click on the '''captaincy data frame'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | cursor in the '''Source''' window.
+
||cursor in the '''Source''' window.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let us view the names of the captains along with the number of matches they have won.
+
||Now let us view the names of the captains along with the number of matches they have won.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on the '''script mydataframe.R'''
+
||Click on the '''script mydataframe.R'''
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
 
'''captaincy[c("names", "won")]'''
 
'''captaincy[c("names", "won")]'''
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, type the following command and press '''Enter'''.
+
 
 +
 
 +
||In the '''Source '''window, type the following command and press '''Enter'''.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight''' c() '''
+
||Highlight''' c() '''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Here''' c''' '''function '''is used''' '''to concatenate '''names '''and '''won'''.  
+
||Here''' c''' '''function '''is used''' '''to concatenate '''names '''and '''won'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight '''names '''and '''won '''
+
||Highlight '''names '''and '''won '''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Observe that''' names''' and '''won''' have been written within double quotes.  
+
||Observe that''' names''' and '''won''' have been written within double quotes.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
+
||Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Save the '''script''' and execute this line.  
+
||Save the '''script''' and execute this line.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Point to the names of the captains in the''' Console''' window.
+
||Point to the names of the captains in the''' Console''' window.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The '''names''' of captains and the number of matches '''won '''are seen in the '''Console''' window.
+
||The '''names''' of captains and the number of matches '''won '''are seen in the '''Console''' window.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let us extract a '''subset '''from '''captaincy data frame'''.
+
||Now let us extract a '''subset '''from '''captaincy data frame'''.
  
<span style="background-color:#ffffff;">We will create a </span><span style="background-color:#ffffff;">'''subset'''</span><span style="background-color:#ffffff;"> of captains,</span><span style="background-color:#ffffff;">''' '''</span><span style="background-color:#ffffff;">who have won more than 30% of their matches. </span>
+
We will create a '''subset''' of captains,''' '''who have won more than 30% of their matches.  
 +
 
 +
This is called slicing a '''data frame'''.
  
<span style="background-color:#ffffff;">This is called slicing a </span><span style="background-color:#ffffff;">'''data frame'''</span><span style="background-color:#ffffff;">. </span>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | click on the '''captaincy data frame''' in '''Source''' window.
+
||click on the '''captaincy data frame''' in '''Source''' window.
| style="border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, click on the '''captaincy data frame'''.  
+
| | In the '''Source '''window, click on the '''captaincy data frame'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
 +
 
  
 
Highlight '''victory '''column of '''captaincy '''in the '''Source '''window
 
Highlight '''victory '''column of '''captaincy '''in the '''Source '''window
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Please note that there is a </span><span style="background-color:#ffffff;">'''column'''</span><span style="background-color:#ffffff;"> named </span><span style="background-color:#ffffff;">'''victory'''</span><span style="background-color:#ffffff;"> in the </span><span style="background-color:#ffffff;">'''captaincy'''</span><span style="background-color:#ffffff;"> </span><span style="background-color:#ffffff;">'''data frame.'''</span>
+
||Please note that there is a '''column''' named '''victory''' in the '''captaincy''' '''data frame.'''
 +
 
 +
For required '''subset '''of captains, their victory should be greater than 0.3.
  
<span style="background-color:#ffffff;">For required </span><span style="background-color:#ffffff;">'''subset '''</span><span style="background-color:#ffffff;">of captains, their victory should be greater than 0.3. </span>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
 +
 
  
 
Highlight '''names''', '''played '''and '''won '''columns of '''captaincy'''
 
Highlight '''names''', '''played '''and '''won '''columns of '''captaincy'''
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">For this </span><span style="background-color:#ffffff;">'''subset'''</span><span style="background-color:#ffffff;">, we shall only show the </span>
+
 
* <div style="margin-left:1.947cm;margin-right:0cm;"><span style="background-color:#ffffff;">names</span></div>
+
 
* <div style="margin-left:1.947cm;margin-right:0cm;"><span style="background-color:#ffffff;">number of matches </span><span style="background-color:#ffffff;">'''played'''</span></div>
+
||For this '''subset''', we shall only show the  
* <div style="margin-left:1.947cm;margin-right:0cm;"><span style="background-color:#ffffff;">number of matches </span><span style="background-color:#ffffff;">'''won'''</span></div>
+
 
 +
* names
 +
* number of matches '''played'''
 +
* number of matches '''won'''
 +
 
 +
 
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on the '''script mydataframe.R'''
+
||Click on the '''script mydataframe.R'''
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | I will resize the '''Source''' window.  
+
||I will resize the '''Source''' window.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
<span style="background-color:#ffffff;">'''subData </span><- subset(captaincy, victory > 0.3, select = c("names", "played", "won"))'''
+
'''subData <- subset(captaincy, victory > 0.3, select = c("names", "played", "won"))'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">In the </span><span style="background-color:#ffffff;">'''Source '''</span><span style="background-color:#ffffff;">window, type </span><span style="background-color:#ffffff;">'''the following command'''</span>
+
||In the '''Source '''window, type '''the following command'''
 +
 
 +
Now, press '''Enter '''after the comma followed by 0 point 3.
  
<span style="background-color:#ffffff;">Now, press </span><span style="background-color:#ffffff;">'''Enter '''</span><span style="background-color:#ffffff;">after the comma followed by 0 point 3. </span>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">You can press </span><span style="background-color:#ffffff;">'''Enter'''</span><span style="background-color:#ffffff;"> after a</span><span style="background-color:#ffffff;">''' comma'''</span><span style="background-color:#ffffff;"> for better visibility. </span>
+
||You can press '''Enter''' after a''' comma''' for better visibility.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
 +
 
  
 
Highlight '''select '''
 
Highlight '''select '''
  
'''print(<span style="background-color:#ffffff;">subData </span>)'''
 
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">The</span><span style="background-color:#ffffff;">''' select parameter'''</span><span style="background-color:#ffffff;"> is used to select the required columns, </span><span style="background-color:#ffffff;">'''names'''</span><span style="background-color:#ffffff;">, </span><span style="background-color:#ffffff;">'''played'''</span><span style="background-color:#ffffff;">, and </span><span style="background-color:#ffffff;">'''won'''</span><span style="background-color:#ffffff;">. </span>
 
  
<span style="background-color:#ffffff;">In the </span><span style="background-color:#ffffff;">'''Source '''</span><span style="background-color:#ffffff;">window, type </span><span style="background-color:#ffffff;">'''print'''</span><span style="background-color:#ffffff;"> within </span><span style="background-color:#ffffff;">'''parentheses subData '''</span><span style="background-color:#ffffff;">.</span>
+
'''print(subData )'''
 +
||The''' select parameter''' is used to select the required columns, '''names''', '''played''', and '''won'''.
 +
 
 +
 
 +
In the '''Source '''window, type '''print''' within '''parentheses subData '''.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight two lines  
+
||Highlight two lines  
  
 
Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
 
Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Save the </span><span style="background-color:#ffffff;">'''script'''</span><span style="background-color:#ffffff;"> and run these two lines. </span>
+
||Save the '''script''' and run these two lines.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">I am resizing the </span><span style="background-color:#ffffff;">'''Console'''</span><span style="background-color:#ffffff;"> window to see the output properly. </span>
+
||I am resizing the '''Console''' window to see the output properly.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the output in the '''Console '''window  
+
||Highlight the output in the '''Console '''window  
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">The </span><span style="background-color:#ffffff;">'''subData '''</span><span style="background-color:#ffffff;">is shown in the </span><span style="background-color:#ffffff;">'''Console'''</span><span style="background-color:#ffffff;"> window.</span>
+
||The '''subData '''is shown in the '''Console''' window.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on the '''captaincy data frame''' in '''Source''' window.
+
||Click on the '''captaincy data frame''' in '''Source''' window.
| style="border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, click on the '''captaincy data frame'''.  
+
| | In the '''Source '''window, click on the '''captaincy data frame'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]  
+
||[RStudio]  
  
  
 
Highlight the third value of fourth column in '''captaincy '''
 
Highlight the third value of fourth column in '''captaincy '''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Finally, let us learn how to extract a particular entry from some </span><span style="background-color:#ffffff;">'''column'''</span><span style="background-color:#ffffff;"> of a </span><span style="background-color:#ffffff;">'''data frame'''</span><span style="background-color:#ffffff;">. </span>
+
||Finally, let us learn how to extract a particular entry from some '''column''' of a '''data frame'''.  
  
  
<span style="background-color:#ffffff;">We will extract the third value in the fourth </span><span style="background-color:#ffffff;">'''column'''</span><span style="background-color:#ffffff;"> of the </span><span style="background-color:#ffffff;">'''captaincy data frame'''</span><span style="background-color:#ffffff;">.</span>
+
We will extract the third value in the fourth '''column''' of the '''captaincy data frame'''.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on the '''script mydataframe.R'''
+
||Click on the '''script mydataframe.R'''
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
||[RStudio]
  
  
 
'''<nowiki>captaincy[[4]][3]</nowiki>'''
 
'''<nowiki>captaincy[[4]][3]</nowiki>'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">In the </span><span style="background-color:#ffffff;">'''Source '''</span><span style="background-color:#ffffff;">window, type </span><span style="background-color:#ffffff;">'''captaincy '''</span><span style="background-color:#ffffff;">within double square brackets </span><span style="background-color:#ffffff;">'''4'''</span><span style="background-color:#ffffff;"> within single square brackets </span><span style="background-color:#ffffff;">'''3'''</span><span style="background-color:#ffffff;">. </span>
+
||In the '''Source '''window, type '''captaincy '''within double square brackets '''4''' within single square brackets '''3'''.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
+
||Press '''Ctrl + S''' >> Press '''Ctrl+Enter''' keys.
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Save the </span><span style="background-color:#ffffff;">'''script'''</span><span style="background-color:#ffffff;"> and execute the current line. </span>
+
||Save the '''script''' and execute the current line.  
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Highlight the output in the </span><span style="background-color:#ffffff;">'''Console '''</span><span style="background-color:#ffffff;">window</span>
+
||Highlight the output in the '''Console '''window
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">The expected value</span><span style="background-color:#ffffff;">''' 14'''</span><span style="background-color:#ffffff;"> is seen in the </span><span style="background-color:#ffffff;">'''Console'''</span><span style="background-color:#ffffff;"> window.</span>
+
||The expected value''' 14''' is seen in the '''Console''' window.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">For more information on </span><span style="background-color:#ffffff;">'''indexing '''</span><span style="background-color:#ffffff;">and </span><span style="background-color:#ffffff;">'''slicing '''</span><span style="background-color:#ffffff;">data frames, please refer to the </span><span style="background-color:#ffffff;">'''Additional materials'''</span><span style="background-color:#ffffff;"> section on this website.</span>
+
||For more information on '''indexing '''and '''slicing '''data frames, please refer to the '''Additional materials''' section on this website.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Let us summarize what we have learnt.
+
||Let us summarize what we have learnt.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
||Show slide
  
 
Summary
 
Summary
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In this tutorial, we have learnt how to:
+
||In this tutorial, we have learnt how to:
* <div style="margin-left:1.947cm;margin-right:0cm;">Extract rows or columns from a '''data frame'''</div>
+
 
* <div style="margin-left:1.947cm;margin-right:0cm;">Create a '''subset''' from a '''data frame '''</div>
+
* Extract rows or columns from a '''data frame'''
* <div style="margin-left:1.947cm;margin-right:0cm;">Retrieve data using double square brackets </div>
+
* Create a '''subset''' from a '''data frame '''
 +
* Retrieve data using double square brackets  
 +
 
 +
 
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Slide 8
+
||Slide 8
  
 
Assignment
 
Assignment
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We now suggest an assignment.
+
||We now suggest an assignment.
* <div style="margin-left:1.947cm;margin-right:0cm;">Create a '''subset '''from '''captaincy data frame''' with the captains who have played > 20 matches and lost < 14 matches. </div>
+
 
 +
* Create a '''subset '''from '''captaincy data frame''' with the captains who have played > 20 matches and lost < 14 matches.  
 +
 
 +
 
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
||Show slide
  
 
About the Spoken Tutorial Project
 
About the Spoken Tutorial Project
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The video at the following link summarises the Spoken Tutorial project.
+
||The video at the following link summarises the Spoken Tutorial project.
  
 
Please download and watch it.
 
Please download and watch it.
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
||Show slide
  
 
Spoken Tutorial Workshops
 
Spoken Tutorial Workshops
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We conduct workshops using Spoken Tutorials and give Certificates.
+
||We conduct workshops using Spoken Tutorials and give Certificates.
  
 
Please contact us.
 
Please contact us.
 +
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Show Slide</span>
+
||Show Slide
  
 
Forum to answer questions
 
Forum to answer questions
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Please post your timed queries in this forum.</span>
+
||Please post your timed queries in this forum.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Show Slide</span>
+
||Show Slide
  
 
Forum to answer questions
 
Forum to answer questions
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Please post your general queries in this forum.</span>
+
||Please post your general queries in this forum.
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Show Slide</span>
+
||Show Slide
  
<span style="background-color:#ffffff;">Textbook Companion</span>
+
Textbook Companion
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">The </span><span style="background-color:#ffffff;">'''FOSSEE '''</span><span style="background-color:#ffffff;">team coordinates the </span><span style="background-color:#ffffff;">'''TBC '''</span><span style="background-color:#ffffff;">project.</span>
+
||The '''FOSSEE '''team coordinates the '''TBC '''project.
 +
 
 +
For more details, please visit these sites.
  
<span style="background-color:#ffffff;">For more details, please visit these sites.</span>
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Show Slide</span>
+
||Show Slide
  
 
Acknowledgement
 
Acknowledgement
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India
+
||The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India
 +
 
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Show Slide</span>
+
||Show Slide
  
 
Thank You
 
Thank You
| style="background-color:#ffffff;border-top:none;border-bottom:1.25pt solid #000001;border-left:1.25pt solid #000001;border-right:1.25pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">The script for this tutorial was contributed by Shaik Sameer (FOSSEE Fellow 2018).</span>
+
||The script for this tutorial was contributed by Shaik Sameer (FOSSEE Fellow 2018).
  
<span style="background-color:#ffffff;">This is Sudhakar Kumar from IIT Bombay signing off. Thanks for watching.</span>
+
 
 +
This is Sudhakar Kumar from IIT Bombay signing off. Thanks for watching.
 
|-
 
|-
 +
 
|}
 
|}

Revision as of 23:07, 19 February 2019

Title of script: Indexing and Slicing Data Frames

Author: Shaik Sameer (IIIT Vadodara) and Sudhakar Kumar (IIT Bombay)

Keywords: R, RStudio, data frames, indexing, slicing, working directory, video tutorial.


Visual Cue Narration
Show slide

Opening slide

Welcome to the spoken tutorial on Indexing and Slicing Data Frames.
Show slide

Learning Objectives


In this tutorial, we will learn how to:
  • Extract rows or columns from a data frame
  • Create a subset from a data frame
  • Retrieve data using double square brackets


Show slide

Pre-requisites


To understand this tutorial, you should have knowledge about
  • Data frames in R
  • R script in RStudio and
  • How to set Working directory in RStudio

If not, please locate the relevant tutorials on R on this website.

Show slide

System Specifications

This tutorial is recorded on
  • Ubuntu Linux OS version 16.04
  • R version 3.2.3
  • RStudio version 1.1.456

Install R version 3.2.0 or higher.

Show slide


Download Files

For this tutorial, we will use the data frame CaptaincyData.csv and a script file mydataframe.R.


Download these files from the Code files link of this tutorial.

[Computer screen]

Highlight CaptaincyData.csv and mydataframe.R in the folder myProject

I have downloaded and moved these files to the folder myProject on my Desktop.


I have also set this folder as my Working Directory.

Let us switch to Rstudio.



Point to script mydataframe.R.

Click mydataframe.R in RStudio


Point to mydataframe.R in Rstudio.

Let us open the script mydataframe.R in RStudio.

For this, click on the script mydataframe.R


Script mydataframe.R opens in Rstudio.

[RStudio]

captaincy <- read.csv("CaptaincyData.csv")

View(captaincy)

Here, we have declared a variable captaincy to store and read CaptaincyData.csv.


Also, View function is being used to see the contents of the file.

Highlight <- symbol in the Source window Remember, you may also use equal to sign in place of less than symbol followed by hyphen.


However, we recommend less than symbol followed by hyphen.


For this, there is a shortcut in RStudio.


Suppose we want to assign a value of 2 to a variable named testvar.


[RStudio]

Alt + -

testvar <- 2

In the Console window, type testvar and then press

Alt and -(hyphen) keys simultaneously.

Then type 2 and press Enter.

Highlight mydataframe.R in the Source window Let us get back to the Source window.

Run the script mydataframe.R by clicking on the Source button.

[RStudio]

Highlight third row of captaincy

Now let us extract the contents of the third row of the captaincy data frame.
Click on the script mydataframe.R
[RStudio]


captaincy[3,]

In the Source window, type captaincy


Type capt and press Enter to make the variable captaincy autocomplete. Now within square brackets 3 followed by comma. And press Enter.


Press Enter key at the end of every command.

Remember one of the most important features of RStudio include intelligent auto-completion of function names, packages, and R objects.

Highlight comma in the Source window We use a comma within square brackets when we wish to extract a row.
Press Ctrl + S >> Press Ctrl+Enter keys. Save the script and execute the current line by pressing Ctrl+Enter keys.
Highlight the output in the Console window The third row of the captaincy data frame is seen in the Console window.
Highlight comma in captaincy[3,] Now, let us run the same command without a comma.
[RStudio]

captaincy[3]

In the Source window, type captaincy then within square brackets 3.
Press Ctrl + S >> Press Ctrl+Enter keys. Save the script and run this line only, as shown earlier.
Highlight the output in the Console window The contents of the third column of the data frame, are displayed on the Console window.
So, to extract a column, we shouldn’t use a comma within the square brackets.

When we extract data using row number or column number, it is known as numeric indexing.

In the Source window, click on the captaincy data frame.
[RStudio]

Highlight second and third rows of captaincy

Let us now extract the contents of second and third rows of the captaincy data frame.
[RStudio]


captaincy[c(2,3),]


To retrieve more than one row, we use a numeric index vector. Click on the script mydataframe.R

In the Source window, type the following command and press Enter.

Highlight the c() function c function is being used to concatenate the second and third rows.
Press Ctrl + S >> Press Ctrl+Enter keys. Save the script and execute the current line.
Highlight the output in the Console window The second and third rows of captaincy data frame are seen in the Console window.
In the Source window, click on the captaincy data frame.
Now, we’ll find who has played 25 matches from the played column of captaincy data frame.

Extracting this type of information is known as logical indexing.

Click on the script mydataframe.R
[RStudio]


captaincy[captaincy$played==25,]

In the Source window, type captaincy

Within square brackets captaincy dollar sign played equal to equal to 25 comma. Press Enter.

Highlight dollar sign


Highlight two equal to signs

Remember, dollar sign allows you to extract elements by name.

Please note that there is no space between the two equal to signs.

Press Ctrl + S >> Press Ctrl+Enter keys. Save the script and execute the current line.
Highlight the output in the Console window The details of captain Dravid are shown in the Console window.
click on the captaincy data frame in Source window. In the Source window, click on the captaincy data frame.
Now let us learn how to get the values of any particular attribute for all the players.

We will fetch the names of all the captains.

[RStudio]

Highlight first column of captaincy

captaincy[1]

For this, we need to know the values in the first column.

Click on the script mydataframe.R

In the Source window, type captaincy and within square brackets 1.

Highlight 1 in square brackets


Please note that I have not used a comma inside the square brackets.
Press Ctrl + S >> Press Ctrl+Enter keys. Save the script and execute the current line.
Highlight the output in the Console window The names of the captains are seen in the Console window.
Usually we use column names instead of column numbers.
[RStudio]

captaincy["names"]

To know the names of the captains, type captaincy.

Within square brackets inside double quotes names

Press Ctrl + S >> Press Ctrl+Enter keys. Save the script and execute the current line.
Point to the names in the Console window. Names of the captains are shown in the Console window.

Extracting data by column names is known as name indexing.

Highlight the broom icon in the Console window Clear the Console window by clicking on the broom icon.
In the Source window, click on the captaincy data frame.
cursor in the Source window. Now let us view the names of the captains along with the number of matches they have won.
Click on the script mydataframe.R
[RStudio]

captaincy[c("names", "won")]


In the Source window, type the following command and press Enter.
Highlight c() Here c function is used to concatenate names and won.
Highlight names and won Observe that names and won have been written within double quotes.
Press Ctrl + S >> Press Ctrl+Enter keys. Save the script and execute this line.
Point to the names of the captains in the Console window. The names of captains and the number of matches won are seen in the Console window.
Now let us extract a subset from captaincy data frame.

We will create a subset of captains, who have won more than 30% of their matches.

This is called slicing a data frame.

click on the captaincy data frame in Source window. In the Source window, click on the captaincy data frame.
[RStudio]


Highlight victory column of captaincy in the Source window

Please note that there is a column named victory in the captaincy data frame.

For required subset of captains, their victory should be greater than 0.3.

[RStudio]


Highlight names, played and won columns of captaincy


For this subset, we shall only show the
  • names
  • number of matches played
  • number of matches won


Click on the script mydataframe.R
I will resize the Source window.
[RStudio]

subData <- subset(captaincy, victory > 0.3, select = c("names", "played", "won"))

In the Source window, type the following command

Now, press Enter after the comma followed by 0 point 3.

You can press Enter after a comma for better visibility.
[RStudio]


Highlight select


print(subData )

The select parameter is used to select the required columns, names, played, and won.


In the Source window, type print within parentheses subData .

Highlight two lines

Press Ctrl + S >> Press Ctrl+Enter keys.

Save the script and run these two lines.
I am resizing the Console window to see the output properly.
Highlight the output in the Console window The subData is shown in the Console window.
Click on the captaincy data frame in Source window. In the Source window, click on the captaincy data frame.
[RStudio]


Highlight the third value of fourth column in captaincy

Finally, let us learn how to extract a particular entry from some column of a data frame.


We will extract the third value in the fourth column of the captaincy data frame.

Click on the script mydataframe.R
[RStudio]


captaincy[[4]][3]

In the Source window, type captaincy within double square brackets 4 within single square brackets 3.
Press Ctrl + S >> Press Ctrl+Enter keys. Save the script and execute the current line.
Highlight the output in the Console window The expected value 14 is seen in the Console window.
For more information on indexing and slicing data frames, please refer to the Additional materials section on this website.
Let us summarize what we have learnt.
Show slide

Summary

In this tutorial, we have learnt how to:
  • Extract rows or columns from a data frame
  • Create a subset from a data frame
  • Retrieve data using double square brackets


Slide 8

Assignment

We now suggest an assignment.
  • Create a subset from captaincy data frame with the captains who have played > 20 matches and lost < 14 matches.


Show slide

About the Spoken Tutorial Project

The video at the following link summarises the Spoken Tutorial project.

Please download and watch it.

Show slide

Spoken Tutorial Workshops

We conduct workshops using Spoken Tutorials and give Certificates.

Please contact us.

Show Slide

Forum to answer questions

Please post your timed queries in this forum.
Show Slide

Forum to answer questions

Please post your general queries in this forum.
Show Slide

Textbook Companion

The FOSSEE team coordinates the TBC project.

For more details, please visit these sites.

Show Slide

Acknowledgement

The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India
Show Slide

Thank You

The script for this tutorial was contributed by Shaik Sameer (FOSSEE Fellow 2018).


This is Sudhakar Kumar from IIT Bombay signing off. Thanks for watching.

Contributors and Content Editors

Madhurig, Sudhakarst