0% found this document useful (0 votes)
41 views17 pages

A Dictionary of Epidemiology - 5th Edition Full Ebook Access

The document is a preface and introduction to 'A Dictionary of Epidemiology, 5th Edition,' which aims to teach epidemiologists and health data analysts how to use R for statistical computing and graphics. It emphasizes the importance of practical skills in data collection and processing, and presents R as a versatile tool for various analytical tasks in public health. The book is structured into three parts, covering data manipulation, basic epidemiology concepts with R, and diverse public health topics, all aimed at making R accessible to epidemiologists.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views17 pages

A Dictionary of Epidemiology - 5th Edition Full Ebook Access

The document is a preface and introduction to 'A Dictionary of Epidemiology, 5th Edition,' which aims to teach epidemiologists and health data analysts how to use R for statistical computing and graphics. It emphasizes the importance of practical skills in data collection and processing, and presents R as a versatile tool for various analytical tasks in public health. The book is structured into three parts, covering data manipulation, basic epidemiology concepts with R, and diverse public health topics, all aimed at making R accessible to epidemiologists.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

A Dictionary of Epidemiology, 5th Edition

Visit the link below to download the full version of this book:

https://medidownload.com/product/a-dictionary-of-epidemiology-5th-edition/

Click Download Now


Preface

We wrote this book to introduce R—a language and environment for statis-
tical computing and graphics—to epidemiologists and health data analysts
conducting epidemiologic studies. From our experience in public health prac-
tice, sometimes even formally trained epidemiologists lack the breadth of an-
alytic skills required at health departments where resources are very limited.
Recent graduates come prepared with a solid foundation in epidemiological
and statistical concepts and principles and they are ready to run a multi-
variable analysis (which is not a bad thing we are grateful for highly trained
staff). However, what is sometimes lacking is the practical knowledge, skills,
and abilities to collect and process data from multiple sources (e.g., Census
data; legally reportable diseases, death and birth registries) and to adequately
implement new methods they did not learn in school. One approach to im-
plementing new methods is to look for the “commands” among their favorite
statistical packages (or to buy a new software program). If the commands
do not exist, then the method may not be implemented. In a sense, they are
looking for a custom-made solution that makes their work quick and easy.
In contrast to custom-made tools or software packages, R is a suite of basic
tools for statistical programming, analysis, and graphics. One will not find a
“command” for a large number of analytic procedures one may want to exe-
cute. Instead, R is more like a set of high quality carpentry tools (hammer,
saw, nails, and measuring tape) for tackling an infinite number of analytic
problems, including those for which custom-made tools are not readily avail-
able or affordable. We like to think of R as a set of extensible tools to imple-
ment one’s analysis plan, regardless of simplicity or complexity. With practice,
one not only learns to apply new methods, but one also develops a depth of
understanding that sharpens one’s intuition and insight. With understanding
comes clarity, focused problem-solving, and confidence.
This book is divided into three parts. First, we cover how to process,
manipulate, and operate on data in R. Most books cover this material briefly
or leave it for an appendix. We decided to dedicate a significant amount of
space to this topic with the assumption that the average epidemiologist is
VIII Preface

not familiar with R and a good grounding in the basics will make the later
chapters more understandable. Second, we cover basic epidemiology topics
addressed in most books but we infuse R to demonstrate concepts and to
exercise your intuition. You may notice a heavier emphasis on descriptive
epidemiology which is what is more commonly used at health departments,
at least as a first step. In this section we do cover regression methods and
graphical displays. Third, we have included “how to” chapters on a diversity of
topics that come up in public health, such as meta-analysis, decision analysis,
and multi-state modeling. Our goal is not to be comprehensive in each topic
but to demonstrate how R can be used to implement a diversity of methods
relevant to public health epidemiology and evidence-based practice.
To help us spread the word, this book is available on the World Wide Web
(http://www.medepi.com). We do not want financial or geographical barriers
to limit access to this material. We are only presenting what we have learned
from the generosity of others. Our hope is that more and more epidemiologists
will embrace R for epidemiological applications, or at least, include it in their
toolbox.

Berkeley, California Tomás Aragón


September 2010
Acknowledgements

I would like to acknowledge the professors at University of California at Berke-


ley that not only taught me the principles and methods of epidemiology, bio-
statistics, and demography, but also introduced me to the S language as a tool
for exploring and analyzing epidemiologic data. More specifically, I owe spe-
cial thanks to Professor Steve Selvin, Chair of the Division of Biostatistics at
the School of Public Health, Professor Kenneth Wachter, Chair of the Depart-
ment of Demography, and Professor Arthur Reingold, Chair of the Division of
Epidemiology. Professor Selvin convinced me that the investment in learning
S would pay off in increased productivity and understanding. From Professor
Wachter I learned the fundamentals of demography and how to use S to pro-
gram functions for demographic analysis. Professor Reingold recruited me to
direct the UC Berkeley Center for Infectious Diseases & Emergency Readiness
where I have had the opportunity and challenge to think about how to make
this material more accessible to public health epidemiologists.
Using the S language is so much fun! It becomes an extension of one’s
analytic mind. Thanks for getting me started and giving me the opportunity
to learn and teach!

Berkeley, California Tomás Aragón


Contents

Part I Working with R

1 Getting Started With R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3


1.1 What is R? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.1 Who should learn R? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.2 Why should I learn R? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.3 Where can I get R? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 How do I use R? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.1 Using R on your computer . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.2 Can I use R on the World Wide Web . . . . . . . . . . . . . . . . 6
1.2.3 Does R have epidemiology programs? . . . . . . . . . . . . . . . . 6
1.2.4 How should I use these notes? . . . . . . . . . . . . . . . . . . . . . . . 7
1.3 Just do it! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3.1 Using R as your calculator . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3.2 Useful R concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3.3 Useful R functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.4 How do I get help? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.3.5 Is there anything else that I need? . . . . . . . . . . . . . . . . . . . 14
1.3.6 What’s ahead? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2 Working with R data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23


2.1 Data objects in R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.1.1 Atomic vs. recursive data objects . . . . . . . . . . . . . . . . . . . . 23
2.1.2 Assessing the structure of data objects . . . . . . . . . . . . . . . 26
2.2 A vector is a collection of like elements . . . . . . . . . . . . . . . . . . . . . 27
2.2.1 Understanding vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2.2 Creating vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.2.3 Naming vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.2.4 Indexing vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.2.5 Replacing vector elements (by indexing and assignment) 39
2.2.6 Operations on vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
XII Contents

2.3 A matrix is a 2-dimensional table of like elements . . . . . . . . . . . . 46


2.3.1 Understanding matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.3.2 Creating matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.3.3 Naming a matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.3.4 Indexing a matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.3.5 Replacing matrix elements . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.3.6 Operations on a matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.4 An array is a n-dimensional table of like elements . . . . . . . . . . . 60
2.4.1 Understanding arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
2.4.2 Creating arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.4.3 Naming arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.4.4 Indexing arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.4.5 Replacing array elements . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.4.6 Operations on arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.5 A list is a collection of like or unlike data objects . . . . . . . . . . . . 75
2.5.1 Understanding lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
2.5.2 Creating lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
2.5.3 Naming lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
2.5.4 Indexing lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
2.5.5 Replacing lists components . . . . . . . . . . . . . . . . . . . . . . . . . 81
2.5.6 Operations on lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
2.6 A data frame is a list in a 2-dimensional tabular form . . . . . . . . 83
2.6.1 Understanding data frames and factors . . . . . . . . . . . . . . . 83
2.6.2 Creating data frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
2.6.3 Naming data frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
2.6.4 Indexing data frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
2.6.5 Replacing data frame components . . . . . . . . . . . . . . . . . . . 91
2.6.6 Operations on data frames . . . . . . . . . . . . . . . . . . . . . . . . . . 91
2.7 Managing data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
2.8 Managing our workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
2.9 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

3 Managing-epidemiologic-data-in-R . . . . . . . . . . . . . . . . . . . . . . . . . 103
3.1 Entering and importing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
3.1.1 Entering data at the command prompt . . . . . . . . . . . . . . . 103
3.1.2 Importing data from a file . . . . . . . . . . . . . . . . . . . . . . . . . . 110
3.1.3 Importing data using a URL . . . . . . . . . . . . . . . . . . . . . . . . 113
3.2 Editing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
3.2.1 Text editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
3.2.2 The data.entry, edit, or fix functions . . . . . . . . . . . . . 114
3.2.3 Vectorized approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
3.2.4 Text processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
3.3 Sorting data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
3.4 Indexing (subsetting) data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
3.4.1 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Contents XIII

3.4.2 Subsetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123


3.5 Transforming data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
3.5.1 Numerical transformation . . . . . . . . . . . . . . . . . . . . . . . . . . 124
3.5.2 Creating categorical variables (factors) . . . . . . . . . . . . . . . 125
3.5.3 “Re-coding” levels of a categorical variable . . . . . . . . . . . 127
3.5.4 Use factors instead of dummy variables . . . . . . . . . . . . . . . 130
3.5.5 Conditionally transforming the elements of a vector . . . 130
3.6 Merging data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
3.7 Executing commands from, and directing output to, a file . . . . 134
3.7.1 The source function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
3.7.2 The sink and capture.output functions . . . . . . . . . . . . . 135
3.8 Working with missing and “not available” values . . . . . . . . . . . . 137
3.8.1 Testing, indexing, replacing, and recoding . . . . . . . . . . . . 139
3.8.2 Importing missing values with the read.table function 140
3.8.3 Working with NA values in data frames and factors . . . . 141
3.8.4 Viewing number of missing values in tables . . . . . . . . . . . 143
3.8.5 Setting default NA behaviors in statistical models . . . . . 144
3.8.6 Working with finite, infinite, and NaN numbers . . . . . . . 145
3.9 Working with dates and times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
3.9.1 Date functions in the base package . . . . . . . . . . . . . . . . . . 146
3.9.2 Date functions in the chron and survival packages . . . 153
3.10 Exporting data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
3.10.1 Exporting to a generic ASCII text file . . . . . . . . . . . . . . . . 153
3.10.2 Exporting to R ASCII text file . . . . . . . . . . . . . . . . . . . . . . 156
3.10.3 Exporting to R binary file . . . . . . . . . . . . . . . . . . . . . . . . . . 158
3.10.4 Exporting to non-R ASCII text and binary files . . . . . . . 159
3.11 Working with regular expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 159
3.11.1 Single characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
3.11.2 Character class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
3.11.3 Concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
3.11.4 Repetition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
3.11.5 Alternation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
3.11.6 Repetition > Concatenation > Alternation . . . . . . . . . . . 165
3.11.7 Metacharacters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
3.11.8 Other regular expression functions . . . . . . . . . . . . . . . . . . . 167

Part II Applied Epidemiology

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Part I

Working with R
1
Getting Started With R

Tomás Aragón September 27, 2010

1.1 What is R?

R is a freely available “computational language and environment for data


analysis and graphics.” R is indispensable for anyone that uses and interprets
data. As medical, public health, and research epidemiologists, we use R in the
following ways:

• Full-function calculator
• Extensible statistical package
• High-quality graphics tool
• Multi-use programming language

We use R to explore, analyze, and understand epidemiological data. We


analyze data straight out of tables provided in reports or articles as well
as analyze usual data sets. The data might be a large, individual-level data
set imported from another source (e.g., cancer registry); an imported matrix
of group-level data (e.g, population estimates or projections); or some data
extracted from a journal article we are reviewing. The ability to quantitatively
express, graphically explore, and describe epidemiologic data and processes
enables one to work and strengthen one’s epidemiologic intuition.
In fact, we only use a very small fraction of the R package. For those who
develop an interest or have a need, R also has many of the statistical modeling
tools used by epidemiologists and statisticians, including logistic and Poisson
regression, and Cox proportional hazard models. However, for many of these
routine statistical models, almost any package will suffice (SAS, Stata, SPSS,
etc.). The real advantage of R is the ability to easily manipulate, explore,
and graph data. Repetitive analytic tasks can be automated or streamlined
with the creation of simple functions (programs that execute specific tasks).
4 1 Getting Started With R

The initial learning curve is steep, but in the long run one is able to conduct
analyses that would otherwise require a tremendous amounts of programming
and time.
You may find R challenging to learn if you are not familiar with statistical
programming. R was created by statistical programmers and is more often
used by analysts comfortable with matrix algebra and programming. However,
even for those unfamiliar with matrix algebra, there are many analyses one
can accomplish in R without using any advanced mathematics, which would
be difficult in other programs. The ability to easily manipulate data in R
will allow one to conduct good descriptive epidemiology, life table methods,
graphical displays, and exploration of epidemiologic concepts. R allows one to
work with data in any way they come.

1.1.1 Who should learn R?

Anyone that uses a calculator or spreadsheet, or analyzes numerical data


at least weekly should seriously consider learning and using R. This includes
epidemiologists, statisticians, physician researchers, engineers, and faculty and
students of math and science courses, to name just a few. We jokingly tell our
staff analysts that once they learn R they will never use a spreadsheet program
again (well almost never).

1.1.2 Why should I learn R?

To implement numerical methods you need a computational tool. On one


end of the spectrum are calculators and spreadsheets for simple calculations,
and on the other end of the spectrum are specialized computer programs for
such things as statistical and mathematical modeling. However, many numer-
ical problems are not easily handled by these approaches. Calculators, and
even spreadsheets, are too inefficient and cumbersome for numerical calcula-
tions whose scope and scale change frequently. Statistical packages are usually
tailored for the statistical analysis of data sets and often lack an intuitive,
extensible, and powerful programming language for tackling new problems ef-
ficiently. R can do the simplest and the most complex analysis efficiently and
effectively.
When you learn and use R regularly you will save significant amounts
of time and money. It’s powerful and it’s free! It’s a complete environment
for data analysis and graphics. Its straightforward programming language
facilitates the development of functions to extend and improve the efficiency
of your analyses.

1.1.3 Where can I get R?

R is available for many computer platforms, including Mac OS, Linux, Mi-
crosoft Windows, and others. R comes as source code or a binary file. Source
1.2 How do I use R? 5

code needs to be compiled into an executable program for your computer.


Those not familiar with compiling source code (and that’s most of us) just
install the binary program. We assume most readers will be using R in the
Mac OS or MS Windows environment. Listed here are useful R links:

• R Project home page at http://www.r-project.org/;


• R download page at http://cran.r-project.org;
• Numerous free tutorials are at http://cran.r-project.org/other-docs.
html;
• R Wiki site at http://wiki.r-project.org/rwiki/doku.php; and
• R Newsletter at http://cran.r-project.org/doc/Rnews/.

To install R for Windows, do the the following:

1. Go to http://www.r-project.org/;
2. From the left menu list, click on the “CRAN” (Comprehensive R Archive
Network) link;
3. Select a geographic site near you (e.g., http://cran.cnr.berkeley.
edu/);
4. Select appropriate operating system;
5. Select on “base” link;
6. For Windows, save R-X.X.X-win32.exe to your computer; and for Mac
OS, save the R-X.X.X-mini.dmg disk image.
7. Run the installation program and accept the default installation options.
That’s it!

1.2 How do I use R?

1.2.1 Using R on your computer

Use R by typing commands at the R command line prompt (>) and pressing
Enter on your keyboard. This is how to use R interactively. Alternatively,
from the R command line, you can also execute a list of R commands that
you have saved in a text file (more on this later). Here is an example of using
R as a calculator:

> 8*4
[1] 32
> (4 + 6)^3
[1] 1000

And, now for an example using R as a spreadsheet. Use the scan function to
enter data at the command line. At the end of each line press the Enter key to
move to the next line. Pressing the Enter key twice complete the data entry.
6 1 Getting Started With R

> quantity <- scan()


1: 34 56 22
4:
Read 3 items
> price <- scan()
1: 19.95 14.95 10.99
4:
Read 3 items
> total <- quantity*price
> cbind(quantity, price, total)
quantity price total
[1,] 34 19.95 678.30
[2,] 56 14.95 837.20
[3,] 22 10.99 241.78

1.2.2 Can I use R on the World Wide Web

Although we highly recommend installing R on your computer, for a variety of


reasons you may not be able to do so. This is not a major problem because you
can run R commands using Rweb. Rweb is a Web-based interface to R that
takes the submitted code, runs R on the code (in batch mode), and returns
the output (printed and graphical). You can try Rweb from the University of
Minnesota Statistics Department1 .

1.2.3 Does R have epidemiology programs?

The default installation of R does not have packages that specifically imple-
ment epidemiologic applications; however, many of the statistical tools that
epidemiologists use are readily available, including statistical models such as
unconditional logistic regression, conditional logistic regression, Poisson re-
gression, Cox proportional hazards regression, and much more.
To meet the specific needs of public health epidemiologists and health
data analysts, we maintain a freely available suite of Epidemiology Tools1: the
epitools R package can be directly installed from within R or downloaded
from the EpiTools Web site2 .
For example, to evaluate the association of consuming jello with a diarrheal
illness after attending a church supper in 1940, we can use the epitab function
from the epitools package. In the R code that follows, the # symbol precedes
comments that are not evaluated by R.

> library(epitools) #load ’epitools’ package


> data(oswego) #load Oswego dataset

1
http://rweb.stat.umn.edu/Rweb/Rweb.general.html
2
http://www.epitools.net
1.2 How do I use R? 7

> attach(oswego) #attach dataset


> round(epitab(jello, ill, method = "riskratio")$tab, 3)
Outcome
Predictor N p0 Y p1 riskratio lower upper p.value
N 22 0.423 30 0.577 1.000 NA NA NA
Y 7 0.304 16 0.696 1.206 0.844 1.723 0.442
> round(epitab(jello, ill, method = "oddsratio")$tab, 3)
Outcome
Predictor N p0 Y p1 oddsratio lower upper p.value
N 22 0.759 30 0.652 1.000 NA NA NA
Y 7 0.241 16 0.348 1.676 0.59 4.765 0.442
> detach(oswego) #detach dataset
The risk of illness among those that consumed jello was 69.6% compared to
57.7% among those that did not consume jello. Both the risk ratio and the odds
ratio were elevated but we cannot exclude random error as an explanation (p
value = 0.44). We also notice that the odds ratio is not a good approximation
to the risk ratio. This occurs when the risks among the exposed and unexposed
is greater than 10%. In this case, the risks of diarheal illness were 69.6% and
57.7% among exposed and nonexposed, respectively.

1.2.4 How should I use these notes?

The best way to learn R is to use it! Use it as your calculator! Use it as
your spreadsheet! Finally read these notes sitting at a computer and use R
interactively (this works best sitting in a cafe that brews great coffee and
plays good music). In this book, when we display R code it appears as if we
are typing the code directly at the R command line:
> x <- matrix(1:9, nrow = 3, ncol = 3)
> x
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
Sometimes the R code appears as it would in a text editor (e.g., Notepad)
before it has been evaluated by R. When a text editor version of R code is
displayed it appears without the command line and without output:
x <- matrix(1:9,3,3)
x
When the R code displayed exceeds the page width it will continue on the
next line but indented. Here’s an example:
agegrps <- c("Age < 1", "Age 1 to 4", "Age 5 to 14", "Age 15
to 24", "Age 25 to 44", "Age 45 to 64", "Age 64+")

You might also like