Operators Flashcards
<-
What does this operator do
Assign a value to a variable
x <- 10
Assigns the value 10 to x
=
What does this operator do
Another way to assign a value to a variable
x = 10
Assigns the value 10 to x
?
What does this operator do
acts as help button
opens a webpage that provides details about the function
?mean
Will display the help information for the mean function
c()
What does this operator do
Combines values into a vector
my_vector <- c(1, 2, 3, 4, 5)
Pipe Operator
%>%
What does this operator do
Take result of one command and send to next command
filter (age > 30) %>%
select(name, age)
result = data %>%
can think of it as saying “and then”
:
What does this operator do
Creates a sequence of numbers
seq <- 1:5
Creates the vector c(1, 2, 3, 4, 5)
$
What does this operator do
Extract specific columns from a data frame
ages <- data$age
This will output the age column (eg 25, 30, 32)
+
What does this operator do
Add numbers
sum <- 5 + 3
Result is 8
-
What does this operator do
Subtract numbers
difference <- 10 - 4
Result is 6
*
What does this operator do
Multiply numbers
product <- 6 * 7
Result is 42
/
What does this operator do
Divide numbers
quotient <- 20 / 4
Result is 5
==
What does this operator do
Check if two values are equal
is_equal <- (x == 10)
Returns TRUE if x is 10
!=
What does this operator do
Check if two values are not equal
is.not.equal <- (y != 20)
Returns TRUE if y is not 20
<
What does this operator do
Check if left value is less than right value
is_less <- (5 < 10)
Returns TRUE
>
What does this operator do
Check if left value is greater than right value
is.greater = (15 > 10)
Returns TRUE
<=
What does this operator do
Check if left value is less than or equal to right value
is.less.equal <- (10 <= 10)
Returns TRUE
> =
What does this operator do
Check if left value is greater than or equal to right value
is.greater.equal = (15 >= 20)
Returns FALSE
&
What does this operator do
logical AND operator
BOTH conditions must be TRUE
condition <- (x == 10 & y == 20)
TRUE if both are true
|
What does this operator do
logical OR operator
at least ONE condition must be TRUE
condition <- (x == 10 | y == 10)
TRUE if either is true
!
What does this operator do
logical NOT operator
negates truth value of a condition
not_condition <- !(x == 10)
TRUE if x is NOT equal to 10