We will look at the code to add new columns to an R data frame. A new column may be a new feature or a copy of an existing column. We'll look at an example in the following exercise. Adding new features can help in improving the efficiency of a model.
In this exercise, we will add columns to an existing R data frame. These new columns can be dummy values or copies of other columns.
- Add a new feature to the R data frame, as follows:
#Adding new features to a R datadrame
- Load the GermanCredit dataset:
- Assign the GermanCredit value to a new field:
#Assign the value to the new field
GermanCredit$NewField1 <- 1
- Print the GermanCredit string:
The output is as follows:
Figure 3.10: Section showing the added NewField
- Copy an existing column into a new column, as follows:
#Copy an existing column into a new column
GermanCredit$NewField2 <- GermanCredit...