Code Monkey home page Code Monkey logo

Comments (2)

JosiahParry avatar JosiahParry commented on July 3, 2024

To understand s3 you need to understand some other things first

Objects in R
Common Base R types
Atomic vectors
On top of those are data.frames and matrix

Matrix are just vectors they get their special behavior from two things: first their class and then attributes

Let's look at attributes first. Attributes are essentially metadata for any R object.

View all attributes of objects with attributes() view a specific attribute with attr(x, "attr-name")

Set attributes with attr()

When we look at a matrix they have a dims attribute. This tells you how many columns and rows there are.

This, along with the "class" makes this vector a matrix with all the special behaviors of a matrix.

Now the difference between class and type is an important distinction. The ye TYPE always refers to the base R object type. Whereas the class can be any attribution on top of those.

So a matrix is a vector type with an attribute and a class. An object can have multiple classes. There is often a base class (the basic R type) and then a "sub class" on top of that

One thing to note while we're on the topic of matrix is that since they're just a single vector with special attributes that means they have all the same limitations as a normal vector. That means it can only hold the same amount of data as a vector

Now, let's avert our attention to the data.frame. It's type is a list.

It has attributes row names and col names

It also has

NOTE HELPER FUNCTION unclass() to see what an object really is

from youtube-tutorials.

JosiahParry avatar JosiahParry commented on July 3, 2024

S3 methods can be extended by other people! You cannot modify non-s3 functions to work with your custom objects. You would need a wrapper function. With s3 you allow your code to be extensible.

from youtube-tutorials.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.