Download Unix User Guide

Transcript
CHAPTER 3 IMPORTING AND EXPORTING DATA
> z
[[1]]:
[1] "Tom" "Joe" "Dave"
[[2]]:
[1] 93 47 18
[[3]]:
[1] 37 42 43
S-PLUS creates a list with separate components for each field specified in the
what list. You can turn this into a matrix, with the subject names as column
names, as follows:
> matz <- rbind(z[[2]],z[[3]])
> dimnames(matz) <- list(NULL, z[[1]])
> matz
[1,]
[2,]
Tom Joe Dave
93 47
18
37 42
43
You can scan files containing multiple line records by using the argument
multi.line=T. For example, suppose you have a file heart.all containing
information in the following form:
johns 1
450 54.6
marks 1 760 73.5
. . .
You can read it in with scan as follows:
> scan(’heart.all’,what=list("",0,0,0),multi.line=T)
[[1]]:
[1] "johns" "marks" "avery" "able" "simpson"
. . .
[[4]]:
[1] 54.6 73.5 50.3 44.6 58.1 61.3 75.3 41.1 51.5 41.7 59.7
[12] 40.8 67.4 53.3 62.2 65.5 47.5 51.2 74.9 59.0 40.5
68