Functions & Methods in R Flashcards

1
Q

What is the use of getwd() method ?

A

Get present working directory .

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

What is the use of require() method ?

A

It is used for searching a library is installed or not .
require(packageName)

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

What is the use of library() method ?

A

This method is used to include packages in R Code
library(packageName)

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

What is the use of length() method ?

A

This method is used to know how many members are in list , vector , dataframe etc.

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

What is the use of class() method ?

A

This method is used to know object type of variable , like integer,chars,numeric, etc.

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

What is the use of typeof() method ?

A

This Method is used to know Data Structure or container of object.
typeof(variable)

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

What is the use of str() method ?

A

str() method is used to know structure of Data Frame

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

What is the use of is.na() method ?

A

This method is used to find Null valeus in dataFrame
IT returns TRUE or FALSE value
my_vec4 = c(1, 2, NA, 4)
is.na(my_vec4)
is.na(dataFrame$column)

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

What is the use of anyNA() method,
How we use it ?

A

This method is used to know , if vector or data frame has any NA value or not
anyNA(my_vector)
anyNA(dataFrame$column)

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

What is the use of c() method ?

A

This method is used to create vectors .

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

What is the use of seq() method ?

A

This method is used to create vectors
my_vect= seq(from=1, to=10, by=1)

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

What is the use of list() method

A

This function f is used to create list object.
my_list= list(24,’MyName’,c(‘A’,’B’,’C’))

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

What are the use of names() function ?

A

names() function is used to create slots of list on column names
my_list = list(24,’Name’,c(‘A’,’B’,’C’))
names(my_list) =c(‘Col-1’,’Col-2’,’Col-3’)

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

What is the use of matrix() function and what is the proper format to use the function ?

A

Matrix function is used to create matrix.
my_matrix= matrix(c(1,2,3,4,5,6,7,8,9),nrow=3,ncol=3,byrow=TRUE)

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

What is the use of rownames() method ?

A

We use a rownames() method into ways,
1. Give the row names while manually creating the data frame
2. Getting or extracting role names from Data frame

rownames() method is used to create a row names in manual data frames
It also be used to get row names of data Frame

rownames(dataFrame)

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

What is the use of colnames() method ?

A

colnames() method is used to create a column names in manual data frames.
It can also be used to fetch column names from dataFrame

17
Q

print() function is used for ?

A

print() function is used to display strings

18
Q

What is the use of setwd() method

A

setwd() is used to set working directory

19
Q

What is the use of head() method ?

A

head() method is used to show first n rows of data Frame
head(DataFrame,5)
It shows first five rows
head(df) By default it shows 6 rose

20
Q

What is the use of tail() method ?

A

tail() method is used to show last n rows of data Frame
tail(DataFrame,5)
It shows last five rows
tail() by default it shows only 6 rows

21
Q

How To know the total row and columns of data frame ?

A

We have to use dim() method
dim(dataFrame)

22
Q

What is the use of nrow() method ?

A

This method is used in 2 ways .
1. While creating Matrix to define rows
2. To get number a rows of data frame

It is used to get total rows in data Frame.
nrow(dataFrame)

It also used in while creating matrix to define rows & columns
mymatrix = matrix(c(1,2,3,4,5,6,7,8,9),nrow=3,ncol=3,byrow=TRUE)

23
Q

What is the use of ncol() method ?

A

This method Can be used into ways:
1. While creating matrix to define number of columns.
2.It is used to get total columns in a data Frame

24
Q

What is the use of levels() method

A

levels() method is used to show Categorised values of of factor

25
Q

What is the use of factor() method?

A

factor() method is used categorised predefined values or column values.

26
Q

What is the use of read.csv() method
And what is the correct format to use the function?

A

read.csv() method You have to create data frame from file

27
Q

What are the use of mean() method?

A

mean() method is is used to calculate average of integer column values by using mean method .

mean(dataFrame$column)

28
Q

What is the use of apply() method
What is the correct format to use this method ?

A

apply() method is used to find mean of all column values at once, mean of rows is also possiible.
apply(dataFrame,2,mean)

29
Q

What is the use of setwd() ?

A

It is used to change working rdirectory.
setwd(‘pathToDirectory’)

30
Q

What options are used in read.csv method while creating dataFrame ?

A

header , row.names , streingAsFactors

  1. header = TRUE ,means treat first row as col names
  2. row.names = 1 , means treat 1st column as row name
  3. stringAsFactors = FALSE