.1 10 7 .2 10 15 .3 10 19 .4 10 23 .1 20 15 .2 20 13 .3 20 26 .4 20 38 .1 30 21 .2 30 28 .3 30 31 .4 30 47Reading across, this says that the first patient took a dose of .1, with 10 units of water, and experienced 7 units of relief.
We can read this into S-PLUS (calling the data frame ``ex1''):
> ex1 <- read.table("example1") > ex1 V1 V2 V3 1 0.1 10 7 2 0.2 10 15 3 0.3 10 19 4 0.4 10 23 5 0.1 20 15 6 0.2 20 13 7 0.3 20 26 8 0.4 20 38 9 0.1 30 21 10 0.2 30 28 11 0.3 30 31 12 0.4 30 47S-PLUS reads the data into a 12-row, 3-column matrix (just like the file) and labels the rows (the observations) 1 through 12 and the columns (the variables) V1, V2 and V3. These columns can be given more descriptive names by making an assignment to the
names
attribute of ex1
.
> names(ex1) <- c("Dose","Water","Relief")And to check that it worked:
> names(ex1) [1] "Dose" "Water" "Relief" > ex1 Dose Water Relief 1 0.1 10 7 2 0.2 10 15 3 0.3 10 19 4 0.4 10 23 5 0.1 20 15 6 0.2 20 13 7 0.3 20 26 8 0.4 20 38 9 0.1 30 21 10 0.2 30 28 11 0.3 30 31 12 0.4 30 47We could have saved a step by specifying the column names in the
read.table
command:
> ex1 <- read.table("example1", col.names=c("Dose", "Water", "Relief"))