Create data objects in R
In this exercise you will create several types of data objects in R. First you will create a scalar object with one value that can then be used to compute other scalar objects. You will also create three vectors: one with numeric values, one with character values and one with logical TRUE and FALSE values.
This exercise is part of the course
R For SAS Users
Exercise instructions
- Assign the value of
1to an objectx, then create an objectwby adding4tox. - Create a vector object
yconsisting of three numbers5,2and3. - Create a vector object
zconsisting of three words"red","green","blue". - Create a logical object
vwith the first two elements TRUE and last element FALSE.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Assign the value of 1 to an object x
___ <- 1
# Create object w by adding the value 4 to x
___ <- ___ + ___
# Create vector object y
y <- c(___, ___, ___)
# Create a vector z
___
# Create a logical object v
___