A vector of positive integers (letters, and Letters return the 26 lowercase and uppercase letters, respectively).

> letters [1 : 3]

[1] "a" "b" "c"

> letters [c(2,4,6) ]

[1] "b" "d" "f'"

> LETTERS [1 : 3]

[1] "A" "B" "C"

> LETTERS [ c(2,4,6) ]

[1] "B" "D" "E"

> letters

[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m"

[14] "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"

>

> LETTERS

[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M"

[14] "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"

>

> letters [1]

[1] "a"

>

> letters [14]

[1] "n"

> Letters [1]

[1] "A"

> LETTERS [14]

[1] "N"

> letters [c(12,20,26) ]

[1] "1" "t" "z"

→ The elements of a vector can be named.

Using these names, we can access the vector elements.

names is used for functions to get or set the names of an object.

> z <- list (al = 1, a2 = "c" , a3 = 1 :3)

> z

$al

[1] 1

$a2

[1] "c"

$a3

[1] 1 2 3

> names (z)

[1] "a1" "a2" "a3"

List can be heterogeneous (mixed modes).

We can start with a heterogeneous list, give it dimensions, and thus create a heterogeneous matrix that is a mixture of numeric and character data:

> ab <- list (1, 2, 3, "x", "y" , "z")

> dim(ab) <- c(2,3)

> print(ab)

[,1] [,2] [,3]

[1,] 1 3 "y"

[2,] 2 "x" "z"

> letters [1 : 3]

[1] "a" "b" "c"

> letters [c(2,4,6) ]

[1] "b" "d" "f'"

> LETTERS [1 : 3]

[1] "A" "B" "C"

> LETTERS [ c(2,4,6) ]

[1] "B" "D" "E"

> letters

[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m"

[14] "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"

>

> LETTERS

[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M"

[14] "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"

>

> letters [1]

[1] "a"

>

> letters [14]

[1] "n"

> Letters [1]

[1] "A"

> LETTERS [14]

[1] "N"

> letters [c(12,20,26) ]

[1] "1" "t" "z"

**String vector**→ The elements of a vector can be named.

Using these names, we can access the vector elements.

names is used for functions to get or set the names of an object.

> z <- list (al = 1, a2 = "c" , a3 = 1 :3)

> z

$al

[1] 1

$a2

[1] "c"

$a3

[1] 1 2 3

> names (z)

[1] "a1" "a2" "a3"

**Matrices created from Lists**List can be heterogeneous (mixed modes).

We can start with a heterogeneous list, give it dimensions, and thus create a heterogeneous matrix that is a mixture of numeric and character data:

**Example**> ab <- list (1, 2, 3, "x", "y" , "z")

> dim(ab) <- c(2,3)

> print(ab)

[,1] [,2] [,3]

[1,] 1 3 "y"

[2,] 2 "x" "z"

## 0 Comments:

## Post a Comment