Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Interactive Data Entry

To interactively load some data into a vector we can use the scan function which can, for example, read data you type until it finds an empty line:

> ds <- scan()
1: 54 56 57 59
5: 63 64 66 68
9:
Read 8 items
> ds
[1] 54 56 57 59 63 64 66 68

Alternatively, we may have a simple list of numbers in one of our windows on the screen and simply wish to load this into R. For example, select the list of numbers below, assuming we are reading this document on the screen (e.g., we hold down the left mouse button while highlighting the list of numbers):

54 56 57 59 63 64 66 68 68 72 72 75 76 81 84 88 106

In the R console window specify the filename to be the special name, clipboard, and the selected numbers will be read. For example:

> ds <- scan("clipboard")
Read 17 items
> ds
 [1]  54  56  57  59  63  64  66  68  68  72  72  75  76  81  84  88 106

All of the above read the data into a vector. An alternative is to load data into a data frame. Similar approaches are possible. Suppose we have this height and weight data for 30 eleven year old girls attending Heaton Middle School, Bradford UK (http://www.sci.usq.edu.au/staff/dunn/Datasets/Books/Hand/Hand-R/height-R.html, Hand 96).



Height	Weight
135	26
146	33
153	55
154	50
139	32
131	25
149	44
137	31
143	36
146	35
141	28
136	28
154	36
151	48
155	36
133	31
149	34
141	32
164	47
146	37
149	46
147	36
152	47
140	33
143	42
148	32
149	32
141	29
137	34
135	30

We can also place the data into a string within R and read the data from directly from the string:

lines <- "Height
54 
56 
57 
59 
63 
64 
66 
68 
68 
72 
72 
75 
76 
81 
84 
88 
106
"
ds <- read.table(textConnection(lines), header = TRUE)

Another example, reading a table of data:

x <- "Obs   SD   Mean
   1    1.5   6
   2    0.3   8"
obs <- read.table(textConnection(x), header=TRUE, as.is=TRUE)

plot(1:10, type="n" )
text(c(1.2, 2, 3), 8, labels=names(xx), cex=.7)
arrows(.75,7.75, 3.5, 7.75, length=0)
text(c(1.2, 2, 3), 7.5, labels=xx[1,], cex=.7)
text(c(1.2, 2, 3), 7.0, labels=xx[2,], cex=.7)
arrows(.75, 6.75,3.5, 6.75, length=0)

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