Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Clipboard Data

Suppose you are reviewing a small sample of data on the screen in any application (e.g., browsing a web site with some sample data). You want to load the data into R. This can be easily accomplished by selecting or highlighting the data with the mouse and telling R to read from the clipboard.

As an example, visit one of the UCI Machine Learning Repository datasets, such as: http://www.ics.uci.edu/~mlearn/databases/autos/imports-85.data. Highlight the first few rows of the data and then run the following read.table function with the file function identifying the clipboard to be read from:

> autos <- read.csv(file("clipboard"), header=FALSE)
> autos

  V1 V2          V3  V4  V5  V6          V7  V8    V9  V10   V11  V12  V13  V14
1  3  ? alfa-romero gas std two convertible rwd front 88.6 168.8 64.1 48.8 2548
2  3  ? alfa-romero gas std two convertible rwd front 88.6 168.8 64.1 48.8 2548
3  1  ? alfa-romero gas std two   hatchback rwd front 94.5 171.2 65.5 52.4 2823

   V15  V16 V17  V18  V19  V20 V21 V22  V23 V24 V25   V26
1 dohc four 130 mpfi 3.47 2.68   9 111 5000  21  27 13495
2 dohc four 130 mpfi 3.47 2.68   9 111 5000  21  27 16500
3 ohcv  six 152 mpfi 2.68 3.47   9 154 5000  19  26 16500

You can also use scan, for example, to read data from the clipboard into a vector or list:

> x <- scan("clipboard", what="")
Read 7 items
> x
[1] "Age"   "Gender"  "Salary"  "Home" "Vehicle"  "Address"  "Married"

To try this out yourself, select the list of strings and run the scan function.

You can also write to the clipboard:

> write.table(ds, "clipboard", sep="\t", row.names=FALSE)



Copyright © Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010