Lecture 1 Flashcards

Intro to R Commands in R Functions in R Navigation hints Variables in R Multiple Values in Variables Using Packages

1
Q

what’s on the RHS of RStudio (working environment)

A

output, variables

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

what’s on the LHS of RStudio

A
top = instructions to R
bottom = console, type commands into R, get output back immediately
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

does it matter to have space or no space in basic arithmetic in R console? (eg: 10*3 vs 10 * 3)

A

no

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

what is the numerical operator commanding ‘power’? (eg: 2 to the power of 3)

A

numerical operator: ^

eg: 2^3

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

what is the numerical operator commanding ‘multiplication’? (eg: 2 multiplied by 3)

A

numerical operator: *

eg: 2*3

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

what is the numerical operator commanding ‘division’? (eg: 2 divided by 3)

A

numerical operator: /

eg: 2/3

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

what is the numerical operator commanding ‘summation’? (eg: 2 summed by 3)

A

numerical operator: +

eg: 2+3

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

what is the numerical operator commanding ‘subtraction’? (eg: 2 subtracted by 3)

A

numerical operator: +

eg: 2+3

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

what is the logical operator commanding ‘equality’? (eg: 2 + 2 is equal to 4)

A

logical operator: ==

eg: 2+2 == 4

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

what is the logical operator commanding ‘inequality’? (eg: 2 + 2 is NOT equal to 5)

A

logical operator: !=

eg: 2+2 != 5

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

what is the R’s response to logical operators?

A

[1] TRUE
or
[1] FALSE

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

what is the logical operator commanding ‘greater than’? (eg: 4 is greater than 2)

A

logical operator: >

eg: 4 > 2

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

what is the logical operator commanding ‘greater than equal to’? (eg: 2 is greater than equal to 2)

A

logical operator: >=

eg: 2 >= 2

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

what is the logical operator commanding ‘less than’? (eg: 2 is less than 4)

A

logical operator: <

eg: 2 < 4

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

what is the logical operator commanding ‘less than equal to’? (eg: 2 less than equal to 5)

A

logical operator: <=

eg: 2 <= 5

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

if T is TRUE, what would R response be when you input ‘T & T’

A

T & T = if T is TRUE AND T is TRUE, then output would be TRUE

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

if T is TRUE, what would R response be when you input ‘T | T’

A

the logical operator ‘|’ means OR

hence T is TRUE OR T is TRUE, then output is TRUE

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

if T is TRUE, what would R response be when you input ‘T | !T’

A

the logical operator ‘|’ means OR and the logical operator ! means NOT (!T = False)
hence T is TRUE OR NOT T is TRUE, then output is TRUE

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

if T is TRUE, what would R response be when you input ‘T & !T’

A

the logical operator ‘&’ means AND and the logical operator ! means NOT
hence it reads: T is TRUE AND NOT T is TRUE, then output is FALSE

20
Q

what is T & F, T | F, T & !F, T | !F ???

A

FALSE, TRUE, TRUE, TRUE

21
Q

what is F & T, F | T, F & !T, F | !T

A

FALSE, TRUE, FALSE, FALSE

22
Q

what is the function sqrt() for

A

square root

23
Q

what would Sqrt() show

A

ERROR because functions in R are case-sensitive. square root function is sqrt() and not Sqrt()

24
Q

what is the function round()

A

round up or round down

25
Q

> round(3.24) ????

A

[1] 3

26
Q

what is an argument in function?

A

function is like a machine, it needs an argument for the machine to operate.

eg: to make orange juice (output) you need juice maker machine (function) and inside the maker u need orange fruits (argument)

a function would always expect one or more argument (eg: pancakes is made of milk, butter, eggs)

27
Q

> round(3.14159, 4) ???

A

in this case function round () has more than 1 argument.
the argument means that you wanna round 3.14159 to 4 decimal places

hence,
[1] 3.1416

28
Q

> round(2, 3.14159) ?????

A

means that you wanna round 2 to 3.1415 significant figures –> order matters in functions!

hence,
[1] 2

29
Q

nesting function properties?

A

it works inside out. hence, the functions inside is worked out first, then after that outside

30
Q

types of variables?

A
  • numerical: blackbox
31
Q

what kind of variable is age

A

numerical variable

32
Q

if age

A
  1. 44
  2. 64

adding a number to a variable does not change the content of that variable. age is still 34 even thought we added it by 10 in 1

33
Q

if q

A

ERROR

34
Q

requirement for variable names?

A
  1. must start with a letter or a period
  2. letters, numbers, periods c (“0” to “9”) can be used
  3. underscore (_) can be used, but is best avoided
  4. name CANNOT contain space or characters like ?,+,!, #, %, (, ), etc
  5. cannot contain reserved word like TRUE or functions used in R
35
Q

can you have underscore (_) in your variable name?

A

yes. underscore can be used, but is best avoided

36
Q

can variable name contain space?

A

no. CANNOT contain space

37
Q

can you put characters like ? in your variable name?

A

no, name CANNOT contain space or characters like ?,+,!, #, %, (, ), etc

38
Q

can you put a function name in your variable name?

A

no. cannot contain reserved word like TRUE or functions used in R

39
Q

advantages of creating vectors

A

they can store multiple values

they can be combined into data frames

40
Q

types of vectors

A
  • numeric (atomic) vector –> number
  • character (atomic) vector –> name
  • logical (atomic) vector –> TRUE or FALSE
41
Q

what does “c()” function mean

A

it is basically saying to put all these values into this particular variable

eg:
> age age
[1] 34 2

age contains the values 34 and 2. 1st element is 34 and 2nd element is 2

42
Q

what type of vector is involved in this console:

> nerd nerd
[1] TRUE FALSE

A

logical (atomic) vector.

43
Q

vector must:

A

contain the same time to be understandable.

eg: you can’t have numeric and character elements under the same vector at the same time

44
Q

if:

> person subject mark mark [subject == “RMHI”] ?????

A

what it means:
marks for people in RMHI

[1] 82 71

45
Q

if:

> person subject mark subject [mark >= 65 ]

A

what it means:
subject where people get greater or equal to 65

[1] “RMHI”, “RMHI”, “ARMP”

46
Q

if:

> person subject mark mark [person == “ann” &+ subject == “RMHI” &+ mark < 50]

A

what it means:
mark of people who’s name is ANN, takes RMHI, and has mark above 50

response:
numeric (0)

since mark is numeric and there is no element that satisfy those criteria, then numeric (0) is just a vector that contains no elements

47
Q

what is a package in R?

A
  • collection of user-written collections of functions, data.
  • 12000 packages in R
  • installed (in your computer)
  • loaded (made available for use in R session)