Skip to Content
Practical Predictive Analytics
book

Practical Predictive Analytics

by Ralph Winters
June 2017
Beginner to intermediate
576 pages
15h 22m
English
Packt Publishing
Content preview from Practical Predictive Analytics

Eliminating duplicate records

In many cases, you will only want to retain one record that results from a join. Let's say we only want to keep one record for each memberid, and we want it to be the highest TotalPurchase for each member. To eliminate duplicates, we can first sort the data frame by memberid and TotalPurchase amount. Then we will use the rev and duplicated functions to keep only the last purchase record for each memberid. This will leave us with one record for each of the original 1,000 members:

join3 <- join3[order(join3$memberid, join3$TotalAmount),] View(join3) dedup <- join3[!rev(duplicated(rev(join3$memberid))),] nrow(join3) nrow(dedup) > nrow(join3) [1] 1105 > nrow(dedup) [1] 1000 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Superstream: Analytics Engineering

Data Superstream: Analytics Engineering

Alistair Croll, Anna Filippova, Emilie Schario, Lewis Davies, Jacob Frackson, Benn Stancil, Nick Acosta, Elizabeth Caley
R: Predictive Analysis

R: Predictive Analysis

Tony Fischetti, Eric Mayor, Rui Miguel Forte
Python: Advanced Predictive Analytics

Python: Advanced Predictive Analytics

Ashish Kumar, Joseph Babcock

Publisher Resources

ISBN: 9781785886188Supplemental Content