4.1.3 Index 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 Sample Data and Partition Data.
Oracle Machine Learning for R 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 4-4 Indexing an ore.frame Object
This example demonstrates character and integer indexing. The example uses the ordered SPAM_PK
ore.frame
object as shown in the example with title Ordering Using Keys in Chapter 2. 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.
# 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 This Example
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