MKT 715 - M2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What key strokes symbolize an Inequality Operator?

!=

if statements

"if" condition triggers a printout in R; For example... x <- -3 if(x < 0) { print("x is a negative number") }

How would you select a column in R?

# li_df is pre-loaded in your workspace # Select the second column, named day2, from li_df: second li_df$day2

& and |

# linkedin exceeds 10 but facebook below 10 linkedin > 10 & facebook < 10 # When were one or both visited at least 12 times? linkedin >= 12 | facebook >= 12 # When is views between 11 (exclusive) and 14 (inclusive)? views > 11 & views <= 14

Be cautious of a double ampersand

*It only evaluates the first elements of both vectors. For example... c(TRUE, TRUE, FALSE) && c(TRUE, FALSE, FALSE) Prints: TRUE; both elements are "TRUE", thus it prints true.

Be cautious of a double OR operator ("||")

*It only evaluates the first elements of both vectors. For example... c(TRUE, TRUE, FALSE) || c(TRUE, FALSE, FALSE) Prints: TRUE; the first are both "TRUE", thus it prints true.

Less than or equal to

<= and >=

What key stroked symbolize an Equality Operator?

==

Logical Operators and Vectors

AND operator c(TRUE,TRUE,FALSE) & c(TRUE,FALSE,FALSE) Prints: TRUE FALSE FALSE OR operator c(TRUE, TRUE, FALSE) | c(TRUE,FALSE,FALSE) Prints: TRUE, TRUE, FALSE NOT operator !c (TRUE, TRUE, FALSE) Prints: FALSE, FALSE, TRUE

else is statement

Additional conditions to code... R checks these codes in order to evaluate their truthiness. It ignores other print statements when it finds what it needs. Notice there are 3 statements below: x <- 0 if(x < 0) { print("x is a negative number") } else if (x ==0) { print("x is zero") } else { print("x is a positive number") Print out in this case, given that x = 0 : "x is zero"

"NOT" operators

An exclamation point before logical statement; this results in the logically opposite script. For example... !TRUE FALSE; Because not true is false. !FALSE TRUE; Because not false is true.

help( ) function

Displays help topics for many functions in R; can also be inputted as ?sd, sd being the function to search.

"OR" operators

Evaluates a set of arguments and determines if ONE of the arguments is true. For example... y <- 4 y < 5 | y > 15 TRUE; the top argument is true. However... y <- 14 y < 5 | y > 15 FALSE; BOTH arguments are false.

"AND" operators

Evaluates a set of arguments in tandem and produces a "TRUE" or "FALSE" script based upon results. Must ALL be true to be considered true. For example... x <- 12 x > 5 & x < 15 TRUE However... x <- 17 x > 5 & x < 15 FALSE; The second part of the argument is false.

Why is "Hello" greater than "Goodbye" in R?

H comes after G in the alphabet - R does values in character strings

args( ) function

Helpful to learn about the arguments of a function w/o having to read through the R documentation.

Error in library(ggplot2) : there is no package called 'ggplot2'...

It means that you didn't successfully install it. This is an example of an "error message".

Optional Arguments

Notice that both trim and na.rm have default values. This makes them optional arguments.

You must specify a non-default argument...

Otherwise an error message will occur. Argument "x" is missing, with no default.

else statements

Prints out another statement when the "if" condition is not met. You can only use an "else" statement in combination with an "if" statement. It's important that the else keyword comes on the same line as the closing bracket of the if part! x <- -3 if(x < 0) { print("x is a negative number") } else { print("x is either a positive number or zero") } Print out: "x is a negative number" However... X = 5 this time.... x <- 5 if(x < 0) { print("x is a negative number") } else { print("x is either a positive number or zero") } Print out: "x is either a positive number or zero"

abs( ) function

Returns the absolute value on an input.

How do you install a package?

There are two ways to install an R package: an easy way and a more advanced way. Method One 1)Click on the "Packages" tab. 2)Click on "Install" next to Update. 3)Type the name of the package under "Packages (separate multiple with space or comma):" In this case, type ggplot2. 4)Click "Install." Method Two An alternative but slightly less convenient way to install a package is by typing install.packages("ggplot2") in the console pane of RStudio and pressing Return/Enter on your keyboard. Note you must include the quotation marks around the name of the package. Much like an app on your phone, you only have to install a package once. However, if you want to update a previously installed package to a newer version, you need to reinstall it by repeating the earlier steps.

Why is "TRUE" greater than "FALSE" in R?

Under the hood, "TRUE" corresponds (or, coerces) to 1, while "FALSE" corresponds (or, coerces) to 0.

How do you select a variable from a data set?

Using the money sign; dataset$variable

What does (na.rm = TRUE) mean?

When na. rm is TRUE, the function skips over any NA values. However, when na. rm is FALSE, then it returns NA from the calculation being done on the entire row or column.

What is na.rm?

When using a dataframe function na.rm in r refers to the logical parameter that tells the function whether or not to remove NA values from the calculation. It literally means NA remove. It is neither a function nor an operation. It is simply a parameter used by several dataframe functions. They include colSums(), rowSums(), colMeans() and rowMeans(). When na.rm is TRUE, the function skips over any NA values. However, when na.rm is FALSE, then it returns NA from the calculation being done on the entire row or column.

How do you open a package in R?

With the library( ) argument.

Functions use parenthesis?

Yes

Do you always have to load a package after you close RStudio?

Yes; If you exit out of RStudio, you HAVE to reload the package again.

What is the shortcut for an assignment variable in RStudio?

alt, dash

is.numeric

check to see if string is numbers. For example... is.numeric(5) TRUE !is.numeric("hello") TRUE However... !is.numeric(5) FALSE is.numeric("hello") FALSE

The mean default function

mean(x, trim = 0, na.rm = FALSE, ...) x is required; if you do not specify it, R will throw an error. trim and na.rm are optional arguments: they have a default value which is used if the arguments are not explicitly specified.


Kaugnay na mga set ng pag-aaral

Menschen B1.1 - 1 Ihr seid einfach die Besten

View Set

Phys6C Ch42 Nuclear Energy; Effects and Uses of Radiation

View Set

AP Computer Science Unit 8, AP Computer Science Unit 9

View Set

Unit 28: Record Keeping Requirements under SEC 17a-3 & 4

View Set