Create composite object types
In this exercise you will investigate different types of data objects. There are four objects loaded for you in your environment: vectors numvec1
, numvec2
, charvec
and logicvec
which each have 3 elements.
numvec1
is a numeric vector with values 1, 2, 3;numvec2
is a numeric vector with values 5, 2, 3;charvec
is a character vector with values "red", "green", "blue";logicvec
is a logical vector with values TRUE, TRUE, FALSE.
You can view each by typing the name of the object in the console. You will use these objects to create two new composite objects:
- a numeric matrix
nummtx
- a dataframe
dataframe
This exercise is part of the course
R For SAS Users
Exercise instructions
- Create a numeric matrix named
nummtx
with numeric vectorsnumvec1
andnumvec2
which has 2 columns and 3 rows. - Create a dataframe named
dataframe
from the four vectorsnumvec1
,numvec2
,charvec
andlogicvec
. - Get the structure of the dataframe
dataframe
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create matrix with numvec1 and numvec2 with 2 columns, 3 rows
___ <- matrix(c(___, ___), ___, ___)
# Create dataframe from numvec1, numvec2, charvec and logicvec
___
# Get the structure of dataframe
___