R Programming Flashcards

1
Q

How to create a vector in R?

A

Use the c() function which means to combine the elements into a vector. For example:
apple

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

How to create a list in R?

A

A list is an R-object which can contain many different types of elements inside it like vectors, functions and even another list inside it.

list1

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

How to create Matrices in R?

A

A matrix is a two-dimensional rectangular data set. It can be created using a vector input to the matrix function.
M = matrix( c(‘a’, ‘a’, ‘b’, ‘c’, ‘b’ , ‘a’), nrow = 2, ncol = 3, byrow =TRUE).
print(M)
“a” “a” “b”
“c” “b” “a”

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

How to create arrays in R?

A

The array function has an advantage being created with any number of dimensions. For example:
A

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

How to create a data frame in R?

A

Data frames are tabular data objects. For example:

BMI

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

What is the basic syntax for creating a matrix in R

A

matrix(data, nrow, ncol, byrow,dimnames)
data: is the input vector which becomes the data elements of the matrix
nrow : number of rows created
ncol: number of columns created
byrow: a logical clue. If TRUE then the input vector elements are arranged by row
dimname: the names assigned to the rows and columns

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

What is lapply()? What is the syntax?

A

lapply() applies a function over a list or a vector. The output of lapply is a list
lapply(list, triple):
where triple is a function applied to each element in a list

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

What is sapply()?

A

sapply() applies a function over a list or vector.It’s ouput is an array

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

What is vapply()?

A

vapply() applies a function over a list or vector. The output is explicitly specified.

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

What is the syntax for the read.csv function

A

read.csv (file, header= False, sep =” , “ )
Where file = the file path i.e where the file is located on your computer
header = default value is False. If the file does have a header row value should be changed to False
sep = default value is “ , “ if the values in the file are separated by tab or semi-colon this should be specified in this argument.

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

What is the separate function used for and what is it’s syntax

A

The separate function separates the values in one column into multiple columns. The syntax is as follows
separate(dataframe, column, into*, sep = “-“)
into is a character vector which provides the names of the new variables
In order to use this function the tidyr library must be installed and imported

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

What is the string detect function and what is its syntax

A

The string detect function is used to detect the presence or absence of a pattern in a string.
str_detect(input vector, pattern)

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

What is the unite function and what is it’s syntax

A

The unite function is used to paste together multiple columns into one.
unite(dataframe, name of new column, selection of columns to unite, sep =”_”)

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

What is gather function and when is it typically used.

A

Gather takes multiple columns and collapses into key-value pairs, duplicating all other columns as needed

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