5 Combining data values

 

This chapter covers

  • Creating structures containing grouped data: vectors, lists, data, frames, and more
  • How these interact with missing data
  • Inspecting and querying these new structures

So far we’ve only dealt with single-valued variables, but it’s highly unlikely that your data looks so simple. You need a way to combine values into groups of data that together represent some larger concept. There are many ways to do this in R, and the way you store collections of data can impact how you interact with it later, so let’s see some of the different ways to combine data.

5.1 Simple collections

The simplest way to group together values is with the function c(). Feel free to refer to this function however you like, but the words concatenate, combine, and collect are all good options.

Caution

Because c() is a function, it’s a good idea to avoid naming your variables c, which may be tempting if you start with a and b. Granted, R is very clever at figuring out if you mean to use a variable or function, but having c(c,c) in your code just makes for a confused reader. Using "c" (the character) as a value is probably okay, because you won’t refer to it without the quotes.1 

1  With the exception of functions from some packages, such as ggplot2, that use Non-Standard Evaluation (NSE) in their arguments, which doesn’t require the quotes. That’s a whole other story.

5.1.1 Coercion

 
 
 
 

5.1.2 Missing values

 
 
 
 

5.1.3 Attributes

 
 

5.1.4 Names

 
 
 
 

5.2 Sequences

 
 

5.2.1 Vector functions

 
 

5.2.2 Vector math operations

 
 

5.3 Matrices

 
 

5.3.1 Naming dimensions

 
 

5.4 Lists

 
 
 

5.5 data.frames

 
 

5.6 Classes

 
 

5.6.1 The tibble class

 
 

5.6.2 Structures as function arguments

 
 

5.7 Try it yourself

 
 
 

Terminology

 
 
 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest