1.Programming with R & Python - Segment 1 [Week 1 & 2- Introduction to R] Flashcards

1
Q

What is TIOBE ?

A

Programming language popularity index

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

What is data Wrangling ?

A

Data Wrangling is a process of Transforming raw data into a usable format that is used to transform visualise and analyze .

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

Data Wrangling package in R language

A

TidyVerse Meta Libray

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

WhatTidyVerse Package do?

A

TidyVerse is an Meta library . It has many packages intended for Data Science Applications , like packages for Data Wrangling, Visualisation and more .

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

How to know the popularity of programming language?

A

We have to watch programming language popularity index TIOBE ?

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

What are the common features of R language

A
  1. It can handle any size of data
  2. Fast operators on arrays
  3. Efficient tool for data a wrangling . TidyVerse
  4. High quality graphics output capability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which package is used for high-quality graphics in R ?

A

ggplot2

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

When was R Language Developed ?

A

1993

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

From which Language R is Derived ?

A

R is derived from S Language.
R is an advanced version of S Language

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

What is S Language ?

A

R is an High Level Programming Language , desighned for Statistical Computation ,S stands for Statistics ,The goal of S Language is to give user an interactive experience of statistical Computation

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

Source Code of R is written in which language ?

A

Source code of R is written in C & Fortran , so that it can run on any Platform

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

When & where S Language was Developed ?

A

S Language was developed 1976 by Bell Labs .
(Formerly AT & T) & now Lucent Technologies

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

What is the full form of .ipynb

A

Interactive Python notebook extension

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

Who Controll the Design & Evolution of R Language

A

R is an Open-Source Language, and the Design & Evolution of R Language is controlled by R Core Group & R Foundation

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

R Source code is written in which Language ?

A

C & Fortran

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

How to install R Programming Suite in desktop ?

A

Download RStudio Desktop from Rstudio.com
& R interpretor from cran.r-project.org & R-project.org.
First install R-Interpretor and then Rstudio IDE

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

How to Set Working Directory in R IDE ?

A

Goto Sessions / Set Directory

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

How to set default working Directory in R IDE ?

A

Goto Tools/Global options

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

What are the Drawbacks of Google Colabs

A

You have to install packages every time when you run colab.
Uploaded DataFrame is not available in next time when you start colab
Collab does not support direct support to R Language

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

What languages programming can be done in colab

A

Python , Julia, R

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

How to install packages in Google Colab and R notebook ?

A

install.packages(“packageName”)

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

How to install packages in R IDE console?

A

install.packages(“package name”)

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

How to search for a package in R ?

A

require(“packageName”)

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

How to include installed package in R program ?

A

library(“PackageName”)

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

How to Check R Version ?

A

R.version

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

How to clear console in RStudio

A

ctrl + L

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

How to know the current working Directory from Console?

A

getwd() Function

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

How Many Basic Datatypes are in R ?

A

Total Five Data Types :
1.Char
2.Integer
3.Numeric(Real or Float)
4.Logical
5.Complex

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

How Many Types of Data Structures are in R Language ?

A
  1. Atomic Vector
  2. List
  3. Matrix
  4. Data Frame
  5. Factor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

How to create an integer only Variable ?

A

We have to use
L option after value

my_integer = 48L

L indicates its an integer value

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

How to Create Logic Variable

A

my_logic = TRUE

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

Ways to create an vector in R ?

A

We have three ways :
myvect1 = c(1L, 2L, 3L)
myvect2=1:10
myvect3=seq(from=1, to=10, by=2)

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

What is atomic Vector ?

A

Atomic vector is an Homogenous data structure , it is used to create Single Dimension Arrays of same types

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

What are the two functions to create a vector ?

A

c(10L, 20L,45L)
seq(from=1, to=10, by=1)

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

Which function is used to create a vector of all value types

A

c() function

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

How to know the number of elements in a vector

A

We have to use length function.
length(vector)

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

How to know the object type in a vector ?

A

We have to use class function.
typeof(vector)

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

How to know the type of data structure used ?

A

class(objectType)

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

What is the difference between class and typeof function in R?

A

The class function gives the data structure , while typeof method gives what type of data value in the object.

example -
mylst=list(c(1,2,3))
class(mylist) it gives , it is an object of class list
typeof(mylist) - it gives what type of value it contains, int char etc.

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

How to know the structure of vector ?

A

str(vector)

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

How to know the all null values in a vector

A

is.na(vector)

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

How to know whether a vector has the NA values or not

A

anyNA(vector)

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

Which functions are used to find missing values in a vector ?

A

is.na(vector)
anyNA()

44
Q

What are the special values in R language ?

A

infinity 1/0
0/0
These values are treated as special values

45
Q

What is the starting index value of data structure in R language ?

A

Every index started by one

46
Q

What is the list ?

A

List is a hetrogenous data structure in which we can Store different type of values.

47
Q

How to access elements of a vector ?

A

Vector elements are access by index value and array subscript
vector[1]
vector[2]

48
Q

How to assign new value to an vector element

A

vector[1]=45

49
Q

How to create a list ?

A

We have to use list object with c() Function .
my_list2 = list(1, ‘Name’, c(‘a’, ‘b’, ‘c’))

50
Q

What are slots in data frame ?

A

Slots are column names of List & DataFrame

51
Q

How to give name to slots in a list

A

names(my_list2) = c(‘first’, ‘second’, ‘third’)

52
Q

How to access vales in list by using slots ?

A

Two methods:
names(my_list2) = c(‘first’, ‘second’, ‘third’)
my_list2$first

53
Q

How to modify elements of a list ?

A

Two Methods
my_list2$first = 45

list1[1] = 10

54
Q

What is matrix in R language .

A

Matrix is an Atomic vector data structure of one or two dimensional.

55
Q

How to create a matrix ?

A

We have to use matrix class.
myMatrix2=matrix(c(1,2,3,4,5,6),nrow=3,ncol=2)

56
Q

How data is organised while creating matrix ?

A

By default data is organised by column first.
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6

57
Q

How to organise data by row while creating a matrix ?

A

We have to use a byrow option in matrix function to organised data by row first.
myMatrix2=matrix(c(1,2,3,4,5,6),nrow=3,ncol=2,byrow=TRUE)

 [,1] [,2] [1,]    1    2 [2,]    3    4 [3,]    5    6
58
Q

How to assign row names and column names to a matrix?

A

We have to use row names and column names method
rownames(my_matrix2) = c(‘row1’, ‘row2’)
colnames(my_matrix2) = c(‘col1’, ‘col2’, ‘col3’)

 col1 col2 col3 row1    1    2    3 row2    4    5    6
59
Q

How to access elements of matrix

A

Index method is used
my_matrix2[1, 2]

60
Q

What is data frame in R ?

A

Data frame is very essential data structure in R ,
Data frame is a list of list with each sublist of same length.

61
Q

How to assign Row names and column names to matrix in R language ?

A

rownames(mymatrix)=c(‘Row-1’,’Row-2’,’Row-3’,’Row-4’)
colnames(mymatrix)=c(‘Col-1’,’Col-2’,’Col-3’)

62
Q

What stands for S in S language

A

S means Statistics

63
Q

What is the goal of S language ?

A

The goal of S language is to give user an interactive experience in statistical computation.

64
Q

How to change directory from R console ?

A

setwd(‘Parth to Directory’)

65
Q

What symbol is used for slot ?

A

$ Dollor Symbol is used for slot

66
Q

How to get the structure of matrix

A

We have to use str() method .
str(matrix)

67
Q

How to create Data frame manually ?

A
  1. First create atomic vectors of desired values.
  2. Now create data frame object by using data.frame method.
  3. Now assign Row names and colum names to Data Frame.
    ID = c(‘A’,’B’,’C’,’D’)
    Height=c(165,170,145,180)
    Age = c(40,24,65,34)
    studenData=data.frame(ID,Height,Age)
    rownames(studenData)=c(‘Jhon’,’Sundy’,’Bob’,’Ajit’)
    colnames(studenData)=c(‘ID’,’Height’,’Age’)
68
Q

How to get total order of data frame ?

A

We have to use dim() method ?
dim(dataFrameObject)

69
Q

How to show first N Rows of data frame ?

A

head(dataFrameObject,5)

70
Q

How to show Last N Rows ?

A

tail(dataFrameObject,5)

71
Q

How to get total Row counts

A

nrow(dataFrameObject)

72
Q

How to get total Column counts ?

A

ncol(dataFrameObject)

73
Q

How to get structure of data frame object ?

A

str(dataFrameObject)

74
Q

How to get full data frame with single column only ?

A

To get column with header and rownames ,
studenData[‘Age’]
student$age

75
Q

How to get full data frame with one or more columns From data set ?

A

studenData[c(‘ID’,’Age’)]

76
Q

How to get particular row From dataset?

A

studenData[‘Ajit’, ]

77
Q

How to get particular row, and single colum value from datset

A

We have two Methods:
studentData[‘Ajit’,’Age’]
studentData[‘Ajit’,c(‘Age’)]

78
Q

What is the output of following expression :
studenData[‘Ajit’,c(“Age”)]

A

It give only the value of Age column not the full dataFrame. If single call me is given in that way it only give the value of that colum field.

79
Q

How to get all values only of particular single column ,
from all rows ?

A

We have 2 Methods:
Subscript Method - studentData[[‘Age’]]
Slot Method - studentData$Age
Output - 40 24 65 34

Data Frame
80
Q

How to get single column all values with row names ?

A

studentData[‘Age’]
carData[c(‘disp’)]

81
Q

How to get two columns with all values with row names ?

A

studentData[c(‘Age’,’ID’)]

82
Q

What is the factor in R language ?

A

Factor is a data structure, it is a type of vector that can contain only predefined values and is used to categorise the data. Factors are the data objects which are used to category the data and store it as levels.

83
Q

How to create a factor ?

A

gender=factor(c(‘Male’,’Female’,’Male’,’Female’))

84
Q

Which function is used to see factor categorization ?

A

We have to use level()s method
levels(factorObject)

85
Q

How to modify a factor value ?

A

Modification Does not allow new values, only pre define values are used in modification. Use index value under subscript to modify.
gender=factor(c(‘Male’,’Female’,’Male’,’Female’))
gender[1]=’Female’

86
Q

How R language treats character values in columns ?

A

By default character values in data set Treated as factors by default in R language.

87
Q

How to create data frame from file ?

A
  1. Create a string object of path to data frame
  2. Create a data frame object by using read.csv method

file=’http://openmv.net/file/food-texture.csv’ # Web Path
file=’food-texture.csv’ # Local Path
foodData=read.csv(file,header=TRUE,row.names=1,stringsAsFactors = FALSE)

header=TRUE means treat the First row as column names
row.names=1 means treat the first column as the name of rows
stringsAsFactors = FALSE means tell R not to treat chars int column as factors

88
Q

What is the option to set First row as column names ?

A

header=TRUE

89
Q

What is option to set First column as row names ?

A

row.names=1

90
Q

What is the option to set not to treat Characters in column as factors ?

A

stringsAsFactors = FALSE

91
Q

How to get the structure of data frame ?

A

We have to use str() method.
str(dataFrameObject)

92
Q

How to know how many rows & columns are in the data frame ?

A

We have to use dim() method.
dim(dataFrameObject)

93
Q

How to get total rows in data frame?

A

We have to use nrow() method.
nrow(dataFrameObject)

94
Q

How to get total columns in a data frame ?

A

We have to usecol() method
ncol(dataFrameObject)

95
Q

How to get the mean of all columns or rows , which function?

A

We have to use apply() method.
apply(foodData,2,mean) here 2 is for column & 1 is for row

96
Q

How to calculate mean of integer column

A

mean(foodData$Density)

97
Q

How to get factor of data frame row names ?

A

We have to use romnames() method .

factor(rownames(foodData))

98
Q

How to get a row names of data frame object ?

A

rownames(dataFrameObject)

99
Q

How to get column names of data frame object ?

A

colnames(dataFrameObject)

100
Q

How to get factor of particular column

A

factor(foodData$Density)

101
Q

How to convert ipynb file to R marked down file

A
  1. First install ‘rmarkdown’ package
    install.packages(‘rmarkdown’)
    2.convert-ipynb(xyx.ipynb)
    3.Now .ipynb file is converted to .rmd file
102
Q

How to factor a colum, and compare the result ?

A

To compare the result, we have to use length method.
length(factor(carData$mpg)) 32
length(levels(factor(carData$mpg))) 25

103
Q

What is the output of the this expression ?
foodData[‘B907’,’Oil’]

A

It gives the value only of oil colum

104
Q

When we give single column what it means in the expression ?
foodData[‘B907’,’Oil’]

A

When single column given in the expression it only give the value of that field not the full data frame,And when two Colonel values are given like this foodData[‘B110’,c(‘Oil’,’Density’)] then It gives the full row data frame with column names and role names

105
Q

How to create a factor Classification from column field

A

dataFrame=head(foodData,5)
dataFrame
factor(dataFrame$Crispy)

106
Q

How to Extract first & second row with all columns ?

A

df[1:2, ]

107
Q

What is the order of matrix ?

A

Order of matrix means how many elements are in a matrix m x n .