Book Image

R Object-oriented Programming

By : Black
Book Image

R Object-oriented Programming

By: Black

Overview of this book

This book is designed for people with some experience in basic programming practices. It is also assumed that they have some basic experience using R and are familiar using the command line in an R environment. Our primary goal is to raise a beginner to a more advanced level to make him/her more comfortable creating programs and extending R to solve common problems.
Table of Contents (14 chapters)
4
4. Calculating Probabilities and Random Numbers
12
A. Package Management
13
Index

Basic data structures

The basic data structures used to organize data within the R environment include vectors, lists, data frames, tables, and matrices. Here, we provide details for each of these data structures and demonstrate how to create them. This chapter does not include information about how to read data from a file, and the focus is on the data structures themselves. More information about reading from a file can be found in Chapter 3, Saving Data and Printing Results.

Vectors

The default data structure in R is the vector. For example, if you define a variable as a single number, R will treat it as a vector of length one:

> a <- 5
> a[1]
[1] 5

Vectors represent a convenient and straightforward way to store a long list of numbers. Please see Chapter 1, Data Types, to see more examples of creating vectors. One useful and common way to define a vector is to use the c command. The c command concatenates a set of arguments to form a single vector:

> v <- c(1,3,5,7,-10)
...