The ibmdbR package
The ibmdbR package provides methods to read data from, write data to, and sample data from a Db2® database. It also provides access methods for in-database analytic functions and functions for storing R objects in the database.
- See https://cran.r-project.org/web/packages/ibmdbR/ibmdbR.pdf
- Enter, at the R prompt, a question mark (?) followed by the function name (for example,
?idaShowTables
)
In-database analytic functions
In-database analytic function | Corresponding in-application analytic functions | Description |
---|---|---|
idaArule | arules | Discover relationships among items in transactional data. |
idaKMeans | kmeans | Create a k-means model to analyze data clustering. |
idaLm | lm | Create a linear regression model. |
idaNaiveBayes | naiveBayes | Create a naive Bayes model for predictive analysis. |
idaTree | rpart | Create a decision tree (classification tree or regression tree) model. |
Each model is stored in your database in a set of tables. Each of the tables in this set has a name that contains the name of the model. Deleting or modifying one of these tables would corrupt the entire model. Therefore, it is recommended that you simply ignore these tables and do not work with them directly. Instead, use the In-Database Analytic Models page of the web console to manage your models.
Some in-database analytic functions generate models into which you can feed new data to make predictions based on that new data. For example, you might generate a naive Bayes model based on the height, shoe size, and gender of a particular population. You could then feed new height and shoe-size data into that model to make predictions about the gender of each person in the new data set.
General methods, functions, and operators
For use with an IDA data frame | For use with a data frame | Description |
---|---|---|
as.data.frame | as.data.frame | Load data from an IDA data frame into a data frame |
colnames, cor, cov, dim, head, length, max, mean, min, names, print, sd, summary, var | colnames, cor, cov, dim, head, length, max, mean, min, names, print, sd, summary, var | Same for both data frame and IDA data frame |
idaCreateView | - | Create a view that is based on an IDA data frame |
idaMerge | merge | Merge (join) two tables |
idaSample | sample | Draw a random sample |
[,] | [,] | Select a subset of the data in terms of columns and rows |
Functions for interacting with data in the database
Function | Description |
---|---|
idaShowTables | Show all tables and views in the current schema |
idaExistTable, idaIsView | Check whether table or view exists and check its type |
idaDeleteTable, idaDropView | Delete a table or view |
idaQuery, idaScalarQuery | Query the database |
as.ida.data.frame | Load a data frame into a database and return an IDA data frame that points to it |
Storing R objects in the database
- A private table, to which only that user has access
- A public table, which can be read by other users
?ida.list
at the R prompt.