i

R Programming Complete Tutorial

Data Frame Expansion

Now data frame expansion. In this section, we will add new columns and rows in our data frame.

We have constructed a new data frame trn.data with two vectors of five elements. First, one is trn_type, contains a character vector, and the second one contains the numeric vector.

If we want to create a new column to our data frame, we have to use a new column name using a dollar symbol and assign values on it. In this example, we have created a new column source and assigned a vector of five elements on it.

We have created a new data frame, new.data, with three vectors of one element. We can add this new data frame to the rows of our existing data frame trn.data using rbind(). We can add data frames by column level just using cbind().