Adding new records
For those of you familiar with databases, you may already know how to perform an insert
operation to append a new record to the dataset. Alternatively, you can use an alter
operation to add a new column (attribute) into a table. In R, you can also perform insert
and alter
operations but much more easily. We will introduce the rbind
and cbind
function in this recipe so that you can easily append a new record or new attribute to the current dataset with R.
Getting ready
Refer to the Converting data types recipe and convert each attribute of imported data into the proper data type. Also, rename the columns of the employees
and salaries
datasets by following the steps from the Renaming the data variable recipe.
How to do it…
Perform the following steps to add a new record or new variable into the dataset:
First, use
rbind
to insert a new record toemployees
:> employees <- rbind(employees, c(10011, '1960-01-01', 'Jhon', 'Doe', 'M', '1988-01-01'))
We can then reassign the...