Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Practical Machine Learning with R

You're reading from  Practical Machine Learning with R

Product type Book
Published in Aug 2019
Publisher Packt
ISBN-13 9781838550134
Pages 416 pages
Edition 1st Edition
Languages
Authors (3):
Brindha Priyadarshini Jeyaraman Brindha Priyadarshini Jeyaraman
Profile icon Brindha Priyadarshini Jeyaraman
Ludvig Renbo Olsen Ludvig Renbo Olsen
Profile icon Ludvig Renbo Olsen
Monicah Wambugu Monicah Wambugu
Profile icon Monicah Wambugu
View More author details
Toc

Table of Contents (8) Chapters close

About the Book 1. An Introduction to Machine Learning 2. Data Cleaning and Pre-processing 3. Feature Engineering 4. Introduction to neuralnet and Evaluation Methods 5. Linear and Logistic Regression Models 6. Unsupervised Learning 1. Appendix

Adding Features to a Data Frame

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.

Exercise 29: Adding a New Column to an R Data Frame

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.

  1. Add a new feature to the R data frame, as follows:

    #Adding new features to a R datadrame

    library(caret)

  2. Load the GermanCredit dataset:

    data(GermanCredit)

  3. Assign the GermanCredit value to a new field:

    #Assign the value to the new field

    GermanCredit$NewField1 <- 1

  4. Print the GermanCredit string:

    str(GermanCredit)

    The output is as follows:

    Figure 3.10: Section showing the added NewField
  5. Copy an existing column into a new column, as follows:

    #Copy an existing column into a new column

    GermanCredit$NewField2 <- GermanCredit...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime