# R语言 常用数据结构_R语言培训

3624℃

R语言 常用数据结构

```储存字符型数据
```
```> x = array(rep("a",6),dim=c(2,3))
> x
[,1] [,2] [,3]
[1,] "a"  "a"  "a"
[2,] "a"  "a"  "a"

```
` 储存逻辑型数据`
```> x = array(rep(T,6),dim=c(2,3))
> x
[,1] [,2] [,3]
[1,] TRUE TRUE TRUE
[2,] TRUE TRUE TRUE

```
` 储存数值型数据`
```> x = array(rep(1,6),dim=c(2,3))
> x
[,1] [,2] [,3]
[1,]    1    1    1
[2,]    1    1    1
```

```> x = array(rpois(6,10),dim=c(2,3),dimnames=list(c("male","female"),c("apple","banana","pear")))
> x
apple banana pear
male      13      7    8
female     8     12    7
```

```> x = array(rpois(24,10),dim=c(2,3,4),dimnames=list(c("male","female"),c("apple","banana","pear"),c("Mon","Tue","Wed","Thu")))
> x
, , Mon

apple banana pear
male      11     12   10
female     9      9    9

, , Tue

apple banana pear
male       8     15    7
female     3      5   10

, , Wed

apple banana pear
male       9      9   13
female    12     12    9

, , Thu

apple banana pear
male      11      5    9
female     9      9    8
```

```> x = array(rpois(2,10),dim=c(1,2),dimnames=list(c("apple"),c("male","female")))
> str(x)
int [1, 1:2] 8 15
- attr(*, "dimnames")=List of 2
..\$ : chr "apple"
..\$ : chr [1:2] "male" "female"
> y = as.vector(x)
> str(y)
int [1:2] 8 15
```

`vector(mode = "logical", length = 0)`
`这里，mode参数表示的是该向量储存数据的类型，length表示该向量的长度。`

`matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE,dimnames = NULL)`

```> x = matrix(data=1:6,nrow=2,ncol=3,byrow=T)
> x
[,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
> x = matrix(data=1:6,nrow=2,ncol=3,byrow=F)
> x
[,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
```

```> x = list(fruit=c("apple","banana","pear"),price=c(1,1,1.5),market=c("newabest"))
> x
\$fruit
[1] "apple"  "banana" "pear"

\$price
[1] 1.0 1.0 1.5

\$market
[1] "newabest"
```

```> fruit=c("apple","banana","pear")
> price=c(1,1,1.5)
> x
1  apple   1.0  TRUE
2 banana   1.0 FALSE
3   pear   1.5 FALSE
```

• 在线沟通，请点我在线咨询

• 咨询热线：
13261671783
客服qq：
3285157825