W1: R Functions Flashcards

1
Q

*

/

+

-

A
  • * : Multiply
  • ^ : Power
  • / : Divide
    • : Addition
    • : Subtraction
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does R display output at the start

A

With this: (>)

Example

> 6 - 4/2

[1] 4

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

What are logical operators. == != > >= < <=

A

Provide True or False Response

  • == Equality
  • != Inequality
  • > Greater than
  • >= Greater than or equal to
  • < Less than
  • <= Lesser than or equal to

Example

> 10 < 100

[1] TRUE

> 2 + 2 == 5

[1] FALSE

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

How do we combine logical operators?

&

– !

A
  • &: AND
  • | :OR
  • !: NOT

Example

> c (T & T, T | T, T & !T, T | !T)
[1] TRUE TRUE FALSE TRUE

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

What are functions and arguments

A

Output = Recipe (Ingredient 1, 2, 3, 4)

  • Recipe
    • Function
  • Ingredients
    • Arguments

Example

> sqrt(25)

  • Square root
    • Function
  • 25
    • Argument
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In round (3.14159), which indicate the decimals

A
  • round(3.14159)
    • [1] 3
  • round (3.14159, 2)
    • [1] 3.14
    • 2 indicates decimal place
  • round (2, 3.14159)
    • [1] 2

If argument names are used explicitly, like round (digits = 2, x = 3.14159, then it doesn’t matter

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

What is sqrt( round(4.65, 2) )

A

Nested functions goes from inner most to outer most

  • sqrt( round(4.65, 2) )
  • sqrt (4.65)
  • 2.15
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are variables and values in R. How are they assigned?

A

Variables

  • Storage to store Values

Values are assigned to variables by <-

Example

Box <- “Gandi”

Variable Box now contains value “Gandi”

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

What are the three types of variables are there?

A
  • Numeric
    • Store Numbers
      • Box <- 212.23
  • Character
    • Store Text
      • Box <- “Gandi”
  • Logical
    • Store True/False Values
      • Box <- TRUE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 5 requirements for Variable Names

A
  • Name must start with letter or a period
    • a to z, or A to Z
    • ”.”
  • Letters, periods, numbers (0-9) can be used after
  • Underscore (i.e, “_”) can also be used, but is best avoided (better to use a period)
  • Name cannot contain a space, or characters like ?, +, !, #, $, %, (, ), etc.
  • Name cannot be a reserved word, e.g., TRUE or function, that is used in R.

• Names are case-sensitive, therefore, e.g., myColour is different to mycolour, which are both different to
Mycolour, etc.

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

What are Vectors.

What are elements.

What are some requirements

Hence, what are the types of vectors

A
  • Vectors
    • Variable with >1 values
  • Elements
    • Values in the Vector
  • Requirement
    • Must be the same type, if not R will force them into the same type (Usually character)

Example

  • Numeric (Automic) Vector
    • > age <- c (34,2)
    • > age
    • [1] 34 2
  • Character (Automic) Vector
    • > Name <- c(“Dan”, “Alex”)
    • > Name
    • [1] “Dan” “Alex”
  • Logical (Automic) Vector
    • > Nerd <- c(TRUE, FALSE)
    • > Nerd
    • [1] TRUE FALSE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are advantage of variables

A
  • Store multiple values (vectors), and
  • Be combined into data frames.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Vectors:
- Identifying

  • Dropping
  • Selecting
A

Identify / Select

  • Elements can be identified by its position in the vector
    • e.g. [1] means show 1st
  • If elements have been named, can be identified by name
    • e.g. [“home”]
  • Elements can be selected by its position in the vector
    • e.g. [c (1,3)] means show 1st and 3rd
  • Elements can be selected by logical values or logical statements
    • e.g. [c (TRUE, TRUE, FALSE)] or if like [boredom <.9] will say [TRUE] to those that are true and [FALSE] to vectors which are false

Drop

  • Putting a “-“ sign
    • e.g. [-2] means all vectors except the second one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In the environmental pane, what do Type, Length, Size, and Values indicate

A

Type

  • Variable type

Length

  • No. of elements in the variable

Size

  • Amount of computer memory used by the variable.

Values

  • (some of) the contents of the variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are Data Frames

A

Collection of variables “bundled” together column-wise.
Organised as a case-by-variables matrix

Row:

  • Values for one case or person on all variables.

Column

  • Values for one variable over all cases.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are Factor Variables

A
  • Nominal categorical variables
    • May look like character variables, but they are not
17
Q

What are continuous variables scaled as

A

Stored as numeric type variables in R

But they are not truly continous (Computer limits at 15-17 signif)

18
Q

How do we create factors

A

factor() or as.factor

19
Q

How do we label levels of the factor. Example

A

levels(eyes) <- c( “brown”, “blue”, “green” )

20
Q

What are R Scripts

A

Particular text file (with file type “.R”) that contains all the commands required to undertake the analysis.

21
Q

What does expt$age do. How do we select the first case?

A

expt = From the data file

age = Select the variable

  • expt$age[1] or expt{1, “age”]
22
Q

What is the default rounding for signif

A

Default: 6, but can specify too

  • signif( x = 3.1415926535)
    • [1] 3.14159
  • signif (x = 314159.26535)
    • [1] 314159
  • signif( x = 3141592653.5)
    • [1] 3141590000
  • signif( x = 3.1415926535, digits = 3 )
    • [1] 3.14
23
Q

How do we create headers, bullets, numbers, italics, bolded, italic bolded, superscript, subscript, strike-through (lol)

A
  • Headers: #
  • Bullet: -
  • Numbers: 1
  • Italics: *
  • Bolded: **
  • Italics Bolded: ***
  • Superscript: ^^
  • Superscript: ~ and ~
  • Strike-Through: ~~and~~