2.Programming with R & Python - Segment 2 [Week 3 & 4 -Data Visualisation and Transformation] Flashcards

(72 cards)

1
Q

What is tidyverse ?

A

tidyverse Is a Metal Library in R Language. It is a collection of multiple packages intended for data science applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How many packages are in tidyverse library ?

A

ggplot2
tibble
forcats
purrr
dplyr
tidyr
stringr
readr
lubridate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to create a new notebook in RStudio ?

A

Goto File-NewFile-R-Notebook

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to create a new notebook in RStudio ?

A

Goto File-NewFile-R-Notebook

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to create a new chunk in Rstudio ?

A

ctrl +r

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to run a chunk in Rstudio ?

A

shift + enter or ctr + shift + enter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the inbuilt demo data set in Rstudio ?

A

cars is an inbuilt data set ?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to get the structure of data set ?

A

We have to use str() function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to modify keyboard shortcut in RStudio ?

A

Goto Tool/modify keyboard shortcuts/
Now search for command for which you have to set shortcut like ‘ insert chunk’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to invoke library in Rstudio

A

We have to use require(library) method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which package is used for data Wrangling

A

dplyr Library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to load package in RStudio ?

A

To load package in RStudio we have to use library() function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to load specific package ?

A

To load specific package we have to use library(ggplot2) method .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do invoke inbuilt data sets in RStudio ?

A

data() method is used .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In which package inbuilt data sets are available ?

A

datasets package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to know the description and details of inbuild data set ?

A

Quistion mark sighn followed by dataset name.
?cars

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to load inbuild data sets ?

A

Inbuild data sets are already loaded you have to just use them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the full form of csv ?

A

coma separated values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to list environment variables in work space ?

A

ls()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How to clear workspace environment & console
by running code ?

A

rm(list = ls()) clear variables
cat(‘\014’) clear console

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How to remove single variable from environment ?

A

rm(variableName)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How to remove environment variables using GUI ?

A

You have to click on brush at right hand side on top of Enviroment Pane.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How to add comments in R markdown file ?

A

To write comments we have to use # symbol followed by text
# This is some text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to add new colum to an existing data frame on condition ?

A

We have to use mutate function

carData = mtcars %>% mutate(cylType = ifelse(cyl > 5 ,’High’ , ‘Low’))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is called the process of adding new column to an data frame ?
This process is called mutation or muting a data frame .
26
How to save dataset in a variable ?
carData= mtcars mtcars is an inbuilt Data Set in R
27
What is pipe operator ?
**%>%** Pipe operator is used to pipe data frame to a function or any object.
28
How to add a new column to an existing data set ?
We have two ways to do it , Mutate & Direct Method carData %>% mutate(carColor = 'NotDefined') carData$LaunchYear = "NotDefined"
29
How to add a New column to an existing data set on certain condition ?
``` carData %>% mutate(cylType = ifelse(cyl > 6 , 'High','Low')) ```
30
Adding a column to an existing data set it is temporary or permanent ?
It is temporary, if you want to save permanent then create a new data set object and save changes in that.
31
Add a new column to an existing data set by using the values of a existing data set colum ?
``` carData %>% mutate(wtton = .45 * wt ) ``` Here weight in lbs is converted to tons by using values of wt column
32
How to use condition While adding a new column to an existing data set ?
We have to use ifelse function ? **ifelse(newColumn = condition , Yes,No)** ``` ifelse(cylType = cyl > 6 , 'High' , 'Low') ```
33
Create a new data set by adding two columns to an existing dataSet ?
``` carData.new = carData %>% mutate(cylType = ifelse(cyl > 6 , 'High','Low'),wtton = wt*.45) ```
34
How to get the average of each numeric colum ?
We have to use summary function . summary(carData.new)
35
How to group dataset and get mean of two colums?
We have to use summarise method . ``` carData %>%group_by(cylType) %>% summarise(mean(wtton) , mean(disp)) ```
36
How to brief a column & store the value in Variable?
carData.new %>% summarise(dispavg = mean(disp))
37
How to get the mean of two columns together
carData.new %>% summarise(mean(disp),mean(hp))
38
How to get the mean and no. of elements in a colum , store them in varables ?
carData.new %>% summarise(dispAvg=mean(disp) , n = n())
39
How to group and summarise the values ?
```carData.new %>% group_by(cylType) %>% summarise(mean(wtton),mean(disp)) ```
40
How to extract rows on single conditions ?
We have to use filter() method ``` carData.new %>% filter(cyltype=='High') ```
41
How to extract column on Single conditions ?
We have to use select method. ``` carData.new %>% select(hp) ```
42
How to extract multiple columns ?
carData.new %>% select(hp, wt)
43
How to extract rows on Multiple conditions ?
carData.new %>% filter(cyltype=='High' & mpg > 15)
44
How to extract Required columns only from data set ?
mtcars %>% select(mpg,cyl)
45
If some columns are not required then how can we create a new dataset without them ?
mtcars %>% select(-mpg,-cyl)
46
How to print string & variable together ?
There is two methods for print . ``` num = 25 cat('Number is :',num,'\n') print(paste0('Square of Number is :',num*2)) ```
47
How to use for loop ?
``` for(i in 1:10){ cat('This is - ',i,'\n') } ```
48
Use dataFrame column length to run a for loop ?
``` for(i in 1:ncol(dataFrame)){ cat('This is - ',i,'\n') } ```
49
How to print newline ?
print(paste0(‘\n,)) cat(‘\n’)
50
How to create a Empty Vector of five values ?
``` myvector = vector('integer' , ncol(dataFrame)) ```
51
How to create an empty list ?
mylist = list()
52
How to get sum of vector values ?
We have to use sum() function . sum(myvector)
53
How to use conditional Statements if else ?
Conditional statements are used in two ways ? ifelse(sum(courtDecision)>=3 , 'New Trial Accepted','New Trial Denied') ``` if (sum(courtDecision)>=3) { cat('New Trial Accepted') }else{ cat('New Trial Denied') } ```
54
How to create an plot object ?
`carplot = ggplot(data = carData)`
55
How to assighn variables/Feature to plot object ?
We have to use aesthetic method ,We use mtcars dataset. `carplot = ggplot(data = carData , aes(x = wt , y = disp))`
56
How to add geomatric elements to plot object ?
We have to use geom_point() method . ``` carplot = ggplot(data = carData , aes(x = wt , y = disp)) carplot = carplot + geom_point() ```
57
How to get a row from mtcars data set which have weight of 2.2 and displacement is 78.7
We have to use filter method > `carData %>% filter(wt > 2 & disp < 100)`
58
How to get a row from mtcars data set which have weight of 3.46 and displacement is 225
`carData %>% filter( (wt > 3 & wt < 4) & (disp > 200 & disp < 250) )`
59
How to save plot as image
right click on plot and save it
60
How to add labels to plot object ?
We have to use labs method ``` carplot = carplot + labs(x = 'Weight (1000 lbs)' , y = 'Displacement (cu. in)' , title = 'Weight vs Displacement') ```
61
Which function is used to create plot object ?
ggplot()
62
which function is used to assigh variables to plot object ?
aes() aes(x = wt , y = disp)
63
which function is used to add geomatry to plot object ?
geom_point() carplot = carplot + geom_point()
64
which variable is used in plot object creation method for dataset assighnment ?
data variable data = carData
65
How to rename a column header & overwrite a data frame ?
We have to use rename () method . foodData = foodData %>% rename(OilPercentage = Oil)
66
How to get mean of Oil column in foodtexture dataset ?
mean(foodData$OilPercentage)
67
How to get mean center of Oil column in foodtexture dataset ?
``` foodData$OilPercentageMeanCenter = foodData$OilPercentage - mean(foodData$OilPercentage) ```
68
How to add new column to dataset object ?
We have two methods : **mutate & direct method ** 1. mutate method `foodData = foodData %>% mutate(OilinFood = ifelse(OilPercentage > 16 ,'High','Low'))` 2. Direct mehod `foodData$OilPercentageMeanCenter = foodData$OilPercentage - mean(foodData$OilPercentage)`
69
How to get largest & lowest value of vector ?
We have to use min & max functions : ``` min(foodData$OilPercentage) max(foodData$OilPercentage) ```
70
How to add all values of vector ?
we have top use sum method ``` sum(foodData$OilPercentage) ```
71
How to find the variance by inbuilt method ?
var(foodData$Oil)
72
How many panes are in R Studio ?
We have four ? 1. Source Editor, 2. Console, 3. Workspace Browser (and History), 4. Files (Plots, Packages, Help)