Dose Water Relief Patient .1 10 7 "Homer" .2 10 15 "Marge" ...If we try to read this in, S-PLUS will use the patients' names to label the rows (in place of the numbers one through twelve that it used in previous examples) instead of treating them as a variable. S-PLUS will try to do this any time the data array contains a column of text data with no elements repeated.
> ex5 <- read.table("example5", header=T)
> ex5
Dose Water Relief
Homer 0.1 10 7
Marge 0.2 10 15
Bart 0.3 10 19
Lisa 0.4 10 23
Maggie 0.1 20 15
Burns 0.2 20 13
Smithers 0.3 20 26
Skinner 0.4 20 38
Krabapple 0.1 30 21
Krusty 0.2 30 28
Flanders 0.3 30 31
Sideshow Bob 0.4 30 47
If you want S-PLUS instead to treat the patients' names as a vector, you must specify that S-PLUS should use the null row names (the numbers one through the length of the table, as in previous examples).
> ex5 <- read.table("example5", header=T, row.names=NULL)
> ex5
Dose Water Relief Patient
1 0.1 10 7 Homer
2 0.2 10 15 Marge
3 0.3 10 19 Bart
4 0.4 10 23 Lisa
5 0.1 20 15 Maggie
6 0.2 20 13 Burns
7 0.3 20 26 Smithers
8 0.4 20 38 Skinner
9 0.1 30 21 Krabapple
10 0.2 30 28 Krusty
11 0.3 30 31 Flanders
12 0.4 30 47 Sideshow Bob
If you do want row names but there are none in the file
(like in previous examples), or if you want S-PLUS to treat the
text variables as vectors and use something else for row names, you can
use the row.names argument to read.table which works like
the col.names argument demonstrated in example 1.
Question: How do you read example 6? It is exactly like example 4 in that the data are separated by commas but this time there are no commas between the variable names.At this point you should remove the variables created above from your
.Data area, because you will never need them again.
Type objects() to see what variables you have created,
and then use rm to remove the ones you don't want.
For instance, type rm(ex1) to remove the data frame created
in example 1.