Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
R Object-oriented Programming

You're reading from   R Object-oriented Programming A practical guide to help you learn and understand the programming techniques necessary to exploit the full power of R

Arrow left icon
Product type Paperback
Published in Oct 2014
Publisher
ISBN-13 9781783986682
Length 190 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Kelly Black Kelly Black
Author Profile Icon Kelly Black
Kelly Black
Arrow right icon
View More author details
Toc

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)
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image