Graphics Reference
In-Depth Information
anthoming[, c(
1
,
3
,
2
)]
# Matrix-style indexing
angle ctrl expt
-20 0 1
-10 3 7
0 3 2
10 3 0
20 1 0
In this case, both methods return the same result, a data frame. However, when retrieving a single
column, list-style indexing will return a data frame, while matrix-style indexing will return a vec-
tor, unless you use
drop=FALSE
:
anthoming[
3
]
# List-style indexing
ctrl
0
3
3
3
1
anthoming[,
3
]
# Matrix-style indexing
0 3 3 3 1
anthoming[,
3
, drop
=
FALSE
FALSE
]
# Matrix-style indexing with drop=FALSE
ctrl
0
3
3
3
1
Getting a Subset of a Data Frame
Problem
You want to get a subset of a data frame.