Exercise 1_2_1: Data Types
Johannes Breuer, Stefan Jünger, Veronika Batzdorfer
Introduction to R for Data Analysis
1
Create a numeric vector with at least 6 numbers.
Clues
To create a vector you need the
c()
function.
2
Now, create a character vector with four distinct strings.
Clues
Strings or characters have to be enclosed by quotation marks (
""
or
''
).
3
Let’s turn to more complex data structures. Create a matrix with two columns using the
matrix()
function based on the numeric vector you built in the first exercise.
Clues
You have to either define the
nrow
or
ncol
option to get the proper layout of the matrix.
4
Create a list that includes all of the objects you have created in the previous tasks in this set of exercises.
Clues
Just wrap all elements in the
list()
function
5
Extract the matrix from the list and convert it to a data frame using the
as.data.frame()
function .
Clues
List elements are accessed with
[[]]
.
6
Add some column names (e.g., “first” and “second”) for the two columns of the data frame.
Clues
You can use the same function for setting/changing names as for viewing them.