GBCC

Indexing vectors

speech <- c("four", "score", "and", "seven", "years", "ago", "our", "fathers",
            "brought", "forth", "on", "this", "continent", "a", "new", "nation",
            "conceivedl", "in", "liberty", "and", "dedicated", "to", "the",
            "propostion", "that", "all", "people", "are", "created", "equal")

From the speech vector, extract:

  1. the first element
  2. the 10th element
  3. the first through eighth elements
  4. the first and last element (hint, remember the length() function?)
  5. the second, fifth, ninth and 29th elements
  6. only the even elements
  7. only the odd elements
  8. the 100th element (what happened & why do you think it happened?)

Hint (for 6 & 7): help("Arithmetic")

Also, how many characters are in the 15th element? (Hint: help("nchar")).

Making thing up

What do the following command end up doing in the R console?

seq(1, 100)

seq(1, 100, by=3)

seq(1, 100, length.out=4)

rep(20:30, 2)

rep(20:30, each=2) # why is this different? help("rep")

rep(20:30, each=2, times=2)

Logical?

See what these do and then play with parenthseis.

TRUE | FALSE | FALSE | TRUE | TRUE | FALSE

FALSE | FALSE | FALSE | FALSE | TRUE

TRUE & FALSE & TRUE & FALSE

(TRUE | FALSE) & (TRUE & FALSE)

Hip to be sqrt

result <- cos(sin(log(sqrt(abs(-6*3*2*1)))))
  1. What is the value of result?
  2. Split it into distinct assignment operations and use distinct variable names for each step. For example:
result <- sqrt(abs(-64))

can be broken down into:

step_1 <- abs(-64)
result <- sqrt(step_1)

More Help

Explore:

  • help("Logic")
  • help("typeof")
  • help("class")
  • help("double")
  • help("character")
  • help("integer")
  • help("logical") (NOTE: Using T or F instead of TRUE or FALSE has the same impact on the kitten population as the use of =)
  • help("NA")
  • help("any")
  • help("all")

RStudio

  • Change the theme colors & font (even if you like the base theme/font)
  • Change the pane layout (even if you like the base theme)
  • Explore Help -> Keyboard Shortcuts (it’ll be slightly different on a desktop install) & test some shortcuts
  • Perform some R operations and see what hitting CTRL+l in the console does
  • With one RStudio session open in one browser tab/window, open a new tab/window and try to access http://gbcc-rstudio.dds.ec/

Google for this answer!

You should google for data sets in your area of interest and be prepared to talk about them in the next class.