3.1.3 Indexing Data

You can use integer or character vectors to index an ordered ore.frame object. You can use the indexing to perform sampling and partitioning, as described in "Sampling Data" and "Partitioning Data".

Oracle R Enterprise supports functionality similar to R indexing with these differences:

  • Integer indexing is not supported for ore.vector objects.

  • Negative integer indexes are not supported.

  • Row order is not preserved.

Example 3-4 demonstrates character and integer indexing. The example uses the ordered SPAM_PK and unordered SPAM_NOPK ore.frame objects from Example 2-13. The example shows that you can access rows by name and that you can also access a set of rows by supplying a vector of character row names. The example then shows that you can supply the actual integer value. In the example this results in a set of different rows because the USERID values start at 1001, as opposed to 1.

Example 3-4 Indexing an ore.frame Object

# Index to a specifically named row.
SPAM_PK["2060", 1:4]
# Index to a range of rows by row names.
SPAM_PK[as.character(2060:2064), 1:4]
# Index to a range of rows by integer index.
SPAM_PK[2060:2063, 1:4]
Listing for Example 3-4
R> # Index to a specifically named row.
R> SPAM_PK["2060", 1:4]
       TS USERID make address
2060 2060    380    0       0
R> # Index to a range of rows by row names.
R> SPAM_PK[as.character(2060:2064), 1:4]
       TS USERID make address
2060 2060    380    0       0
2061 2061    381    0       0
2062 2062    381    0       0
2063 2063    382    0       0
2064 2064    382    0       0
R> # Index to a range of rows by integer index.
R> SPAM_PK[2060:2063, 1:4]
       TS USERID make address
3060 3060    380 0.00    0.00
3061 3061    381 0.00    1.32
3062 3062    381 0.00    2.07
3063 3063    382 0.34    0.00