Control Structures Flashcards

Learning if, else, else if statements in R programming languaje

1
Q

if

A

if (a > b) {
print(“a is greater than b”)
}

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

if else

A
if (a > b) {
   print("a is greater than b")
} else {
print("b is greater than a")
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

else if

A
if (a > b) {
   print("a is greater than b")
} else if (a < b) {
   print("b is greater than a")
} else if (a == b) {
   print("a and b are the same")
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

loop: Print elements of a sequence

A

numbers

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

Loop over rows of a data frame

A

for (i in 1:nrow(data_frame)) {
print(data_frame$variable_1[i] + data_frame$variable_2[i])
}

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

Store for-loop output in a vector

A

output_vec

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

for-loop with selection control structure

A
for (i in 1:nrow(data_frame) {
   if (a > b) {
      print("a is greater than b")
} else {
      print("b is greater than a")
      }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

for-loops with more than two cases

A
for (i in 1:nrow(data_frame)) {
   if (a > b) {
      print("a is greater than b")
   } else if (a < b) {
      print("b is greater than a")
   } else if (a == b) {
      print("a and b are the same")
   }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which are the 3 types of control structures?

A

Sequence operations
Selection operations
Repetition operations

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

What do SEQUENCE operations do?

A

perform operation one after another in the order they are specified

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

What do SELECTION operations do?

A

They test whether a specified condition is TRUE or FALSE and executes diferent action depending on that test outcome.

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

What do REPETITION operations do?

A

Allows you to repeat blocks of codes depending on specified conditions.

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