Workshop 1 - Introduction to R
09 Dec 2014
Basic syntax revision
Q1-1.Complete the following table, by
assigning the following entries
(numbers etc) to the corresponding object names and determining the
object class
for each.
Name | Entry | Syntax | Class |
---|---|---|---|
A | 100 | hint | |
B | Big | hint | |
VAR1 | 100 & 105 & 110 | hint | |
VAR2 | 5 + 6 | hint | |
VAR3 | 150 to 250 | hint |
- Print out the contents of the vector you called 'a'. Notice that the output appears on the line under the syntax that you entered, and that the output is proceeded by a [1]. This indicates that the value returned (100) is the first entry in the vector
- Print out the contents of the vector called 'b'. Again notice that the output is proceeded by [1].
- Print out the contents of the vector called 'var1'.
- Print out the contents of the vector called 'var2'. Notice that the output contains the product of the statement rather than the statement itself.
- Print out the contents of the vector called 'var3'. Notice that the output contains 100 entries (150 to 250) and that it spans multiple lines on the screen. Each new line begins with a number in square brackets [] to indicate the index of the entry that immediately follows.
Variables - vectors
Q1-2. Generate the following numeric vectors (variables)
- The numbers 1, 4, 7 & 9 (call the object y)
- The numbers 10 to 25 (call the object y1)
- The sequency of numbers 2, 4, 6, 8...20 (call the object y2)
- The sequency of numbers 2, 4, 6, 8...20 (call the object y2)
Q1-3. Generate the following character vectors (factorial/categorical variables)
- A factor that lists the sex of individuals as 6 females followed by 6 males
- A factor called TEMPERATURE that lists 10 cases of 'High', 10 'Medium & 10 'Low'
- A factor called TEMPERATURE that lists 'High', 'Medium & 'Low' alternating 10 times
- A factor called TEMPERATURE that lists 10 cases of 'High', 8 cases of 'Medium' and 11 cases of 'Low'
Q1-4. Print out the contents of the 'TEMPERATURE' factor. A list of factor levels will be printed on the screen. This will take up multiple lines, each of which will start with a number in square brackets [ ] to indicate the index number of the entry immediately to the right. At the end, the output also indicates what the names of the factor levels are. These are listed in alphebetical order.