Assignments Flashcards

1
Q

What happens if you do the following:
c(1,2,3,4) + c(5,15) ?

A

The second vector is recycled, so you get
6 17 8 19

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

What does the upward arrow do in Rstudio?

A

It gives the previous command

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

What does the tab do?

A

It gives suggestions when you start typing a name of a variable.

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

How do you change your working directory?

A

setwd(‘name’) sets the current working directory to the directory with that name.

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

How do you ask for help/info about a function?

A

Put a ‘?’ in front of it and remove the parentheses.
Example: ?file.exists for the file.exists() function.

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

How do you get the current working directory?

A

getwd()

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

How do you get a list of all the objects in the current workspace?

A

ls()

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

How do you get a list of the files in the current working directory?

A

list.files()

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

How do you create a new directory?

A

dir.create(‘name’)

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

How do you check if a file exists?

A

file.exists(‘name’)

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

How do you create a new filepath name that can be used across platforms?

A

file.path(‘a’, ‘b’)

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

How do you create a directory within a directory?

A

dir.create((‘nametop’, ‘namenested’), recursive = TRUE)

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

How do you get a sequence of the numbers 1 to 20, including 1 and 20?

A

1:20 or seq(1,20)

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

What happens when you use seq(x,y) with real numbers?

A

It gives the sequence from x to y (inclusive) with increments of 1. May never reach y

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

How do you get help/info about an operator like : ?

A

? :
So put the operator between back ‘s

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

How do you adjust the increments when creating a sequence of numbers from x to y?

A

seq(x,y, by = z)
With z the size of increment.

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

What command do you give if you want a sequence of 30 numbers between 5 and 10?

A

seq(5, 10, length=30)

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

What is the best way to get a sequence of numbers with the same length as a vector variable?

A

seq.along(variablename)

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

How do you get the length of a variable?

A

length(variable)

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

How do you create a vector of thirty zeros?

A

rep(0, times=30)

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

How do you create a vector that repeats the pattern 0 1 2 ten times?

A

rep(c(0,1,2), times = 10)

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

How do you create a vector with ten 0s, ten 1s and ten 2s?

A

rep(c(0,1,2), each=10)

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

What are the two types of vectors?

A

Atomic vectors and lists.

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

Atomatic vector

A

Vector that contains only one data type

25
Q

Logical vectors

A

Atomatic vectors that can be only TRUE, FALSE or NA (not available).

26
Q

What do you use to create a character vector?

A

Double quotes: “x”.

27
Q

How do you concatenate and print the elements of a given character vector?

A

paste(vectorname, collapse=” “)

28
Q

How do you join two character vectors v1 and v2?

A

paste(v1, v2, sep=” “)

29
Q

What is LETTERS in R?

A

A predefined character vector that contains all 26 letters of the alphabet.

30
Q

What happens when you use the paste() function on a number vector?

A

It transforms the numbers to characters, so the program will read them as chars.

31
Q

What does NA represent?

A

A missing value.

32
Q

What does an operation involving NA result in?

A

NA

33
Q

How can you make a vector of 100 random values out of two other vectors?

A

sample(c(v1,v2),100)

34
Q

What does is.na(vector) do?

A

It creates a vector with all the values in the vector that are NA.

35
Q

How does R represent TRUE and FALSE?

A

By 1 and 0.

36
Q

What happens if you get the sum of all logical values in R?

A

You essentially get the number of TRUE values, since these are 1.

37
Q

How do you get the sum of all values of a vector?

A

sum(…)

38
Q

What does NaN stand for?

A

not a number

39
Q

What does inf stand for?

A

infinity

40
Q

How do you retrieve a subset from a vector?

A

vectorname[0:10] for slice 0:10.

41
Q

What are the four kinds of index vectors?

A
  1. Logical vectors
  2. Vectors of positive integers
  3. Vectors of negative integers
  4. Character vectors
42
Q

What does x[is.na(x)] do?

A

It gives a vector containing all NAs from x.

43
Q

How do you get for example the 3rd, 5th and 7th element from a vector?

A

vectorname[c(3,5,7)].

44
Q

How do you get all elements of vector v except the second element?

A

v[c(-2)]

45
Q

What is a name vector?

A

A vector that contains both names and numbers, kind of like a 2d vector.

46
Q

How can you give names to a vector v with only numbers?

A

names(v) <- c(“name a”, “name b”, … )

47
Q

How do you check whether two vectors are the same?

A

Identical(v1,v2)

48
Q

What is the difference between a matrix and a data.frame?

A

A matrix can only contain one class of data, a data.frame can contain multiple.

49
Q

How do you get the dimensions of an object x?

A

dim(x)

50
Q

How do you get the class of an object?

A

class(x)

51
Q

How do you make a matrix of r rows and c columns, containing numbers 1 through 20?

A

matrix(data=seq(1,20), nrows = r, ncol =c)

52
Q

What does cbind() do?

A

It combines the columns of for example a vector and a matrix. Implicit coercion then happens.

53
Q

What you need to do if you want to combine different data types?

A

Use data.frame(vector, matrix)

54
Q

What is the difference between && and &, | and || ?

A

The double one && / || evaluates only the first element of a vector whilst the single one & / | evaluates all elements.

55
Q

How do you use a function for checking boolean value?

A

isTRUE(x)

56
Q

What is the function for exclusive or?

A

xor(x)

57
Q

What does which(x) do?

A

It finds the indices of the object that satisfy the constraint, for example which(vector1 >5) gives indices of elements of vector1 that are bigger than 5.

58
Q

How do you get a preview of a dataset saved in a data.frame?

A

head(x) for the first 6 rows, tail(x) for the last. Use argument n=x for x amount of rows.

59
Q

What two functions can you use to get an overview of the data in an object?

A

summary(x) or str(x).