Comments (2)
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.
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)
- Suggested topics?
- Kernel weights to introduce distance decay
- setting up code grip and using it
- rlang: functions for writing functions
- . . . (dots)
- What are simple features?
- scalars are helpful
- raw strings in R wtf
- automating ggplot2: 1000s of plots in seconds!
- Modules in extendr
- Spatial feature engineering
- Why you should stop writing shiny apps HOT 3
- Write dplyr functions the easy way
- rlang::inject vs do.call
- arcgisplaces shiny app
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from youtube-tutorials.