Exercises

  1. Write a program that modifies the function intro() (see Section 1.2.4) so that the person who introduces him or herself states a favorite sport. For example, the result of the following function call:

    intro(name = "Bettina", type = "human", sport = "lacrosse")

    should be:

    ## Hello, I am a human.  
    ## My name is Bettina.
    ## My favorite sport is lacrosse.
  2. Write a program that modifies the function intro() (see Section 1.2.4) so that the person who introduces him or herself says what planet he or she is from. For example, the result of the following function call:

     intro(name = "Zarg", planet = "Jupiter", food = "rubber bands")

    should be:

    ## Hello, my name is Zarg!
    ## My home planet is Jupiter.
    ## I like to eat rubber bands.
  3. Write a program to produce the following output to the console:

    ## *
    ## **
    ## ***
    ## **
    ## *
  4. Write a program to produce the following output to the console:

    ## meow!
    ## hiss!  hiss!
    ## meow!
    ## hiss! hiss! hiss!
    ## meow
  5. Suppose we want to cat “Hello, World” to the console, and we enter:

    cat(Hello, World!)

    What does R say? What did we do wrong?

  6. Suppose we want to cat “Hello, World” to the console, and we enter:

    cat["Hello, World!"]

    What does R say? What did we do wrong?