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

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
Q

What is called the process of adding new column to an data frame ?

A

This process is called mutation or muting a data frame .

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

How to save dataset in a variable ?

A

carData= mtcars

mtcars is an inbuilt Data Set in R

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

What is pipe operator ?

A

%>%
Pipe operator is used to pipe data frame to a function or any object.

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

How to add a new column to an existing data set ?

A

We have two ways to do it ,
Mutate & Direct Method
carData %>% mutate(carColor = ‘NotDefined’)
carData$LaunchYear = “NotDefined”

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

How to add a New column to an existing data set on certain condition ?

A
carData %>% mutate(cylType = ifelse(cyl > 6 , 'High','Low'))
30
Q

Adding a column to an existing data set it is temporary or permanent ?

A

It is temporary, if you want to save permanent then create a new data set object and save changes in that.

31
Q

Add a new column to an existing data set by using the values of a existing data set colum ?

A
carData %>% mutate(wtton = .45 * wt )

Here weight in lbs is converted to tons by using values of wt column

32
Q

How to use condition While adding a new column to an existing data set ?

A

We have to use ifelse function ?
ifelse(newColumn = condition , Yes,No)
~~~
ifelse(cylType = cyl > 6 , ‘High’ , ‘Low’)
~~~

33
Q

Create a new data set by adding two columns to an existing dataSet ?

A
carData.new = carData %>% mutate(cylType = ifelse(cyl > 6 , 'High','Low'),wtton = wt*.45)
34
Q

How to get the average of each numeric colum ?

A

We have to use summary function .
summary(carData.new)

35
Q

How to group dataset and get mean of two colums?

A

We have to use summarise method .
~~~
carData %>%group_by(cylType) %>% summarise(mean(wtton) , mean(disp))
~~~

36
Q

How to brief a column & store the value in Variable?

A

carData.new %>% summarise(dispavg = mean(disp))

37
Q

How to get the mean of two columns together

A

carData.new %>% summarise(mean(disp),mean(hp))

38
Q

How to get the mean and no. of elements in a colum , store them in varables ?

A

carData.new %>% summarise(dispAvg=mean(disp) , n = n())

39
Q

How to group and summarise the values ?

A

```carData.new %>% group_by(cylType) %>% summarise(mean(wtton),mean(disp))
~~~

40
Q

How to extract rows on single conditions ?

A

We have to use filter() method
~~~
carData.new %>% filter(cyltype==’High’)
~~~

41
Q

How to extract column on Single conditions ?

A

We have to use select method.
~~~
carData.new %>% select(hp)
~~~

42
Q

How to extract multiple columns ?

A

carData.new %>% select(hp, wt)

43
Q

How to extract rows on Multiple conditions ?

A

carData.new %>% filter(cyltype==’High’ & mpg > 15)

44
Q

How to extract Required columns only from data set ?

A

mtcars %>% select(mpg,cyl)

45
Q

If some columns are not required then how can we create a new dataset without them ?

A

mtcars %>% select(-mpg,-cyl)

46
Q

How to print string & variable together ?

A

There is two methods for print .
~~~
num = 25
cat(‘Number is :’,num,’\n’)
print(paste0(‘Square of Number is :’,num*2))
~~~

47
Q

How to use for loop ?

A
for(i in 1:10){
    cat('This is - ',i,'\n')
}
48
Q

Use dataFrame column length to run a for loop ?

A
for(i in 1:ncol(dataFrame)){
    cat('This is - ',i,'\n')
}
49
Q

How to print newline ?

A

print(paste0(‘\n,))
cat(‘\n’)

50
Q

How to create a Empty Vector of five values ?

A
myvector = vector('integer' , ncol(dataFrame))
51
Q

How to create an empty list ?

A

mylist = list()

52
Q

How to get sum of vector values ?

A

We have to use sum() function .
sum(myvector)

53
Q

How to use conditional Statements if else ?

A

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
Q

How to create an plot object ?

A

carplot = ggplot(data = carData)

55
Q

How to assighn variables/Feature to plot object ?

A

We have to use aesthetic method ,We use mtcars dataset.
carplot = ggplot(data = carData , aes(x = wt , y = disp))

56
Q

How to add geomatric elements to plot object ?

A

We have to use geom_point() method .
~~~
carplot = ggplot(data = carData , aes(x = wt , y = disp))
carplot = carplot + geom_point()
~~~

57
Q

How to get a row from mtcars data set which have weight of 2.2 and displacement is 78.7

A

We have to use filter method >
carData %>% filter(wt > 2 & disp < 100)

58
Q

How to get a row from mtcars data set which have weight of 3.46 and displacement is 225

A

carData %>% filter( (wt > 3 & wt < 4) & (disp > 200 & disp < 250) )

59
Q

How to save plot as image

A

right click on plot and save it

60
Q

How to add labels to plot object ?

A

We have to use labs method
~~~
carplot = carplot + labs(x = ‘Weight (1000 lbs)’ , y = ‘Displacement (cu. in)’ , title = ‘Weight vs Displacement’)
~~~

61
Q

Which function is used to create plot object ?

A

ggplot()

62
Q

which function is used to assigh variables to plot object ?

A

aes()
aes(x = wt , y = disp)

63
Q

which function is used to add geomatry to plot object ?

A

geom_point()
carplot = carplot + geom_point()

64
Q

which variable is used in plot object creation method for dataset assighnment ?

A

data variable
data = carData

65
Q

How to rename a column header & overwrite a data frame ?

A

<b>We have to use rename () method .</b>
foodData = foodData %>% rename(OilPercentage = Oil)

66
Q

How to get mean of Oil column in foodtexture dataset ?

A

mean(foodData$OilPercentage)

67
Q

How to get mean center of Oil column in foodtexture dataset ?

A
foodData$OilPercentageMeanCenter = foodData$OilPercentage - mean(foodData$OilPercentage)
68
Q

How to add new column to dataset object ?

A

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
Q

How to get largest & lowest value of vector ?

A

We have to use min & max functions :
~~~
min(foodData$OilPercentage)
max(foodData$OilPercentage)
~~~

70
Q

How to add all values of vector ?

A

we have top use sum method
~~~
sum(foodData$OilPercentage)
~~~

71
Q

How to find the variance by inbuilt method ?

A

var(foodData$Oil)

72
Q

How many panes are in R Studio ?

A

We have four ?
1. Source Editor,
2. Console,
3. Workspace Browser (and History),
4. Files (Plots, Packages, Help)