8,9,14 Flashcards

1
Q

expression to say: is not equal to…

A

!=

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

negating the expression 5 == 7

A

5!==7

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

What is the sign for “and”?

What does the sign twice mean?

A

&
`&& version of AND only evaluates the first member of a vector

TRUE & c(TRUE, FALSE, FALSE)
[1] TRUE FALSE FALSE

TRUE && c(TRUE, FALSE, FALSE)
[1] TRUE

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

sign ad double sign for “or”

A

The | version of OR evaluates OR across an entire vector, while the || version of OR only evaluates the first member of a vector.

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

Order of operation for and/or

A

All AND operators are evaluated before OR operators

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

test if arguments are identical?

A

identical(arg1,arg2)

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

find the indices of ints(a vector) that are greater than 7

A

which(ints>7)

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

Use a function to see if any of the elements of ints(the vecotr) are less than zero

A

any(ints<0)

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

Aufbau einer Funktion

A

https://www.google.com/search?q=function+in+r&rlz=1C1CHBF_deDE908DE908&sxsrf=ALeKk007K5cpEoqcvFGaUNypFk8Y97Sm-w:1594731827554&source=lnms&tbm=isch&sa=X&ved=2ahUKEwi_nN-A58zqAhVzwQIHHZxdAMkQ_AUoAnoECAwQBA&biw=1536&bih=722#imgrc=SWdt5wrRWb927M

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

can you pass functions as arguments?

A

Yes

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

using evaluate() along with an anonymous function to return the first element of the vector c(8, 4, 0). Your anonymous function should only take one argument which should be a variable x.

A

evaluate(function(x) {x[1]}, c(8,4,0))

This way you can pass a function as an argument without first defining the passed function. Functions that are not named are appropriately known as anonymous functions.

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

What does … means in a function

A

infinte amount of arguments is allowed.

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

What does paste() do?

A

Concatenates charackter strings like paste(“Programming”, “is”, “fun!”) to “Programming is fun!”

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

structure of a simple if statement

A

if (test_expression) {
statement
}

like in…

x 0){
print(“Positive number”)
}

If the test_expression is TRUE, the statement gets executed. But if it’s FALSE, nothing happens.

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

structure of a simple if else statement

A
if (test_expression) {
statement1
} else {
statement2
}
x  0){
print("Non-negative number")
} else {
print("Negative number")
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Note structure of if else if else with 4 layers

A
if ( test_expression1) {
statement1
} else if ( test_expression2) {
statement2
} else if ( test_expression3) {
statement3
} else {
statement4
}
17
Q

Structure of a for loop

A

for (val in sequence)
{
statement
}

Here, sequence is a vector and val takes on each of its value during the loop. In each iteration, statement is evaluated.

18
Q

Structure of a while loop

A

while (test_expression)
{
statement
}

i

19
Q

Give an example for a break statement. You create a variable sequence from 1 to 5, iterate a for loop over it and want to break if you get to 3. You want to print the result

Same example, but you want to skip 3 so that you print 
1
2
4
5
A

x