Download S-PLUS 8 for Windows User's Guide

Transcript
S-PLUS Language Basics
For greater ease in referring to list components, it is often useful to
name the components. You do this by giving each argument in the
list function its own name. For instance, you can create the same list
as above, but name the components “a” and “b” and save the list data
object with the name xyz:
> xyz <- list(a = 101:119,
+ b = c("char string 1", "char string 2"))
To take advantage of the component names from the list command,
use the name of the list, followed by a $ sign, followed by the name of
the component. For example, the following two commands display
components a and b, respectively, of the list xyz.
> xyz$a
[1] 101 102 103 104 105 106 107 108 109 110 111 112 113
[14] 114 115 116 117 118 119
> xyz$b
[1] "char string 1" "char string 2"
Managing Data
Objects
In S-PLUS any object you create at the command line is permanently
stored on disk until you remove it. This section describes how to
name, store, list, and remove your data objects.
Assigning Data
Objects
To name and store data in S-PLUS, use one of the assignment operators
<- or _. (Do not use the _ character in names!) For example, to create
a vector consisting of the numbers 4, 3, 2, 1 and store it with the name
x, use the c function and type:
> x <- c(4,3,2,1)
You type <- by typing two keys on your keyboard: the “less than” key
(<) followed by the minus (-) character, with no intervening space.
To store the vector containing the integers 1 through 10 in y, type:
> y <- 1:10
The following assignment expressions use the operator _ and are
identical to the two previous assignments above:
> x _ c(4,3,2,1)
> y_1:10
433