R Language Basic Data Structures

Datetime:2016-08-23 01:45:56         Topic: R Program          Share        Original >>
Here to See The Original Article!!!

I wrote an article titled “R Language Basic Data Structures” in the August 2016 issues of Visual Studio Magazine. See https://visualstudiomagazine.com/articles/2016/08/01/r-language-basic-data-structures.aspx .

I program in several different languages. Whenever I’m learning a new language, one of the first thing I want to know about is how the language deals with arrays and lists.

The R language uses some uncommon vocabulary, presumably because the language was designed for statistics problems rather than as a general purpose language.

Anyway, the most basic R data structure is called a vector. It’s very similar to what other languages call an array (fixed number of cells, each holding the same data type such as integer). A second data structure in R is the list. An R list can hold objects of different types and can grow at run time. R lists have some wacky syntax, for example, x <- mylist[[1]] is not the same as x <- mylist[1].

In R, a matrix has exactly two dimensions (row and columns) and each cell must hold the same type. However, in R, an array can have one dimension or two dimensions or three or more dimensions. So a one-dim array is kind of like a vector. A two-dim array is kind of like a matrix. And a three-dim array is closest to an array-of-arrays-of-arrays in languages like C# and Java.

Finally, R has a data frame. A data frame is like a table, and is used by many of the R built-in functions. So a data frame is kind of like a matrix or two-dim array, except data frames columns can hold different types.


Put your ads here, just $200 per month.