Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Modern R Programming Cookbook

You're reading from   Modern R Programming Cookbook Recipes to simplify your statistical applications

Arrow left icon
Product type Paperback
Published in Oct 2017
Publisher Packt
ISBN-13 9781787129054
Length 236 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jaynal Abedin Jaynal Abedin
Author Profile Icon Jaynal Abedin
Jaynal Abedin
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Installing and Configuring R and its Libraries 2. Data Structures in R FREE CHAPTER 3. Writing Customized Functions 4. Conditional and Iterative Operations 5. R Objects and Classes 6. Querying, Filtering, and Summarizing 7. R for Text Processing 8. R and Databases 9. Parallel Processing in R

Defining methods for an S4 class

Like S3 classes, generic functions, and methods, there are similar things also available in the S4 object class. In this recipe, you will create a new method for a generic function for an S4 object class.

Getting ready

To define a new method for an S4 class of object, first you need an object of class S4. Here is the code to create an object of S4 class robustSummary2:

    x <- c(13, 21, 19, 18, 21, 16, 21, 24, 17, 18, 12, 18, 29, 17, 18,   
11, 13, 20, 25, 18, 15, 19, 21, 21, 7, 12, 23, 31, 16, 19, 23,
15, 25, 19, 15, 25, 25, 16, 29, 15, 26, 29, 23, 24, 20, 19,
14, 27, 22, 26)
robSum <- function(obj){
med <- median(obj)
mad <- mad(obj)
q1 <- as.numeric...
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 $19.99/month. Cancel anytime
Banner background image