8,9,14 Flashcards
expression to say: is not equal to…
!=
negating the expression 5 == 7
5!==7
What is the sign for “and”?
What does the sign twice mean?
&
`&& 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
sign ad double sign for “or”
The |
version of OR evaluates OR across an entire vector, while the ||
version of OR only evaluates the first member of a vector.
Order of operation for and/or
All AND operators are evaluated before OR operators
test if arguments are identical?
identical(arg1,arg2)
find the indices of ints(a vector) that are greater than 7
which(ints>7)
Use a function to see if any of the elements of ints(the vecotr) are less than zero
any(ints<0)
Aufbau einer Funktion
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
can you pass functions as arguments?
Yes
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
.
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.
What does … means in a function
infinte amount of arguments is allowed.
What does paste() do?
Concatenates charackter strings like paste(“Programming”, “is”, “fun!”) to “Programming is fun!”
structure of a simple if statement
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.
structure of a simple if else statement
if (test_expression) { statement1 } else { statement2 }
x 0){ print("Non-negative number") } else { print("Negative number") }