Site icon R-bloggers

Object types in R: The fundamentals

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If you’re a self-taught R programmer, you’ve probably grappled with the different kinds of objects you can use in the language. When should you use a list instead of a vector? What’s the difference between a factor and character vector? These questions are easier to answer when you have some of the basics of R’s object types down pat, and Chris Bare lays out the fundamentals quite nicely in his blog post The R Type System. An excerpt:

Because the purpose of R is programming with data, it has some fairly sophisticated tools to represent and manipulate data. First off, the basic unit of data in R is the vector. Even a single integer is represented as a vector of length 1. All elements in an atomic vector are of the same type. The sizes of integers and doubles are implementation dependent. Generic vectors, or lists, hold elements of varying types and can be nested to create compound data structures, as in Lisp-like languages.

He goes on from with useful descriptions and examples of matrices, arrays, data frames, factors and more. Well worth checking out if you want to understand how R’s object types tick.

Digithead’s Lab Notebook: The R type system

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.