Data and Computing Fundamentals

Exercises on R Syntax

Your Name Here

Thu Feb 21 04:26:45 2013

Answer the following by constructing appropriate R commands and/or giving a text narrative.

Object Names

Show that names with different capitalization refer to different objects.

Variable = 1
variable = 2
variable
## [1] 2
Variable
## [1] 1

The name of the object being assigned to always goes to the left of the = operator. What happens if you put it on the right?

3 = Variable
## Error: invalid (do_set) left-hand side to assignment
Variable
## [1] 1

Strings and Names

Show that a string and a name are different.

Assign a string value to an object.

Object = "String"
Object
## [1] "String"

Numbers and Arithmetic

Use scientific notation to create these numbers: 100, 10, 0.001, 0.0000001

100
## [1] 100
10
## [1] 10
0.001
## [1] 0.001
1e-07
## [1] 1e-07

Try these mathematical operations and explain what the values mean:

1/0
## [1] Inf

This produces Inf(inity) because it is a positive number divided by zero.

0/0
## [1] NaN

This produces NaN because it is zero divided by zero.

sqrt(-3)
## Warning: NaNs produced
## [1] NaN

This produces NaNs because it is an imaginary number?

Q: What's the difference between NaN and NA?
A: NaN has an answer, just not one that can be conventionally expressed. NA has none.

Functions and arguments

Show that the order of unnamed arguments makes a difference. Use seq() to illustrate this.

seq(1, 7)
## [1] 1 2 3 4 5 6 7
seq(7, 1)
## [1] 7 6 5 4 3 2 1

Find the names of the arguments to seq(). Show that when you use the names, the order doesn't matter.

What kind of object is created by date()?

date()
## [1] "Thu Feb 21 04:26:45 2013"

String?

Data Frames

Read in the data set “utilities.csv” with fetchData("utilities.csv")

How many rows are there?

What are the names of the variables?

R Markdown Syntax

Write the Markdown to reproduce this outline. See below for a hint.

  1. Sweet
  2. Sour
  3. Savory

Vegetables

  1. Leafy
  2. Flower

Hint:

### Fruits

1. Sweet
    * Apples