Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

R Dataset

Rattle can use a dataset that is already loaded into R (although it will take a copy of it, with memory implications). Only data frames are currently supported, and Rattle will list for you the names of all of the available data frames.

Figure 3.12: Loading an already defined R data frame
Image rattle-rdataset

The data frames need to be constructed in the same R session that is running Rattle (i.e., the same R Console in which you lo the Rattle package). This provides much more flexibility in loading data into Rattle, than is provided directly through the actual Rattle interface.

Figure 3.13: Selected region of a spreadsheet copied to the clipboard
Image gnumeric-date-dollars-selected

This is useful if you have data in a spreadsheet (or any application really) and want to directly paste that data from a clipboard into R. Figure 3.13 illustrates a spreadsheet with three columns of data selected and copied to the clipboard (by the right mouse button menu selecting the Copy option). This data can then be loaded into R quite easily as illustrated in Listing [*]. There, we also convert the date from a string, which is nothing more than a string, into a actual date data type.



[float,caption={Load data from clipboard into \textsf{R}},label={lst:clipboard.into.r}]
> expenses <- read.table(file("clipboard"), header=TRUE)
> expenses$Date <- as.Date(expenses$Date, format="%d-%b-%Y")
> expenses
         Date Expense   Total
1  2005-11-17   19.50   19.50
2  2005-11-23  -15.00    4.50
3  2005-12-10   30.00   34.50
4  2006-01-23 -110.00  -75.50
5  2006-01-28  -20.00  -95.50
6  2006-02-14  -10.00 -105.50
7  2006-02-14  300.00  194.50
8  2006-02-26  220.41  414.91
9  2006-03-03  -20.00  394.91
10 2006-07-14   50.00  444.91
11 2006-07-17   -5.00  439.91
12 2006-09-08 -120.00  319.91
13 2006-09-08 -130.00  189.91
14 2006-10-22   55.00  244.91
15 2006-11-23  135.00  379.91
16 2007-02-11  -90.00  289.91
17 2007-02-22  -20.00  269.91

We can then load this into Rattle directly, as in Figure 3.14.

Figure 3.14: Loading an R data frame originally from the clipboard
Image rattle-rdataset-expenses

As another example, you may want to load data from an SQLite database directly, and have this available in Rattle.

Copyright © 2004-2008 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
PDF version is properly formatted and forms a comprehensive book (draft with over 600 pages).
Brought to you by Togaware.