Operators Flashcards

1
Q

<-

What does this operator do

A

Assign a value to a variable

x <- 10

Assigns the value 10 to x

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

=

What does this operator do

A

Another way to assign a value to a variable

x = 10

Assigns the value 10 to x

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

?

What does this operator do

A

acts as help button
opens a webpage that provides details about the function

?mean

Will display the help information for the mean function

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

c()

What does this operator do

A

Combines values into a vector

my_vector <- c(1, 2, 3, 4, 5)

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

Pipe Operator

%>%

What does this operator do

A

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”

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

:

What does this operator do

A

Creates a sequence of numbers

seq <- 1:5

Creates the vector c(1, 2, 3, 4, 5)

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

$

What does this operator do

A

Extract specific columns from a data frame

ages <- data$age

This will output the age column (eg 25, 30, 32)

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

+

What does this operator do

A

Add numbers

sum <- 5 + 3

Result is 8

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

-

What does this operator do

A

Subtract numbers

difference <- 10 - 4

Result is 6

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

*

What does this operator do

A

Multiply numbers

product <- 6 * 7

Result is 42

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

/

What does this operator do

A

Divide numbers

quotient <- 20 / 4

Result is 5

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

==

What does this operator do

A

Check if two values are equal

is_equal <- (x == 10)

Returns TRUE if x is 10

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

!=

What does this operator do

A

Check if two values are not equal

is.not.equal <- (y != 20)

Returns TRUE if y is not 20

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

<

What does this operator do

A

Check if left value is less than right value

is_less <- (5 < 10)

Returns TRUE

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

>

What does this operator do

A

Check if left value is greater than right value

is.greater = (15 > 10)

Returns TRUE

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

<=

What does this operator do

A

Check if left value is less than or equal to right value

is.less.equal <- (10 <= 10)

Returns TRUE

17
Q

> =

What does this operator do

A

Check if left value is greater than or equal to right value

is.greater.equal = (15 >= 20)

Returns FALSE

18
Q

&

What does this operator do

A

logical AND operator

BOTH conditions must be TRUE

condition <- (x == 10 & y == 20)

TRUE if both are true

19
Q

|

What does this operator do

A

logical OR operator

at least ONE condition must be TRUE

condition <- (x == 10 | y == 10)

TRUE if either is true

20
Q

!

What does this operator do

A

logical NOT operator

negates truth value of a condition

not_condition <- !(x == 10)

TRUE if x is NOT equal to 10