您的位置:首页 > 其它

【R语言学习】split函数

2016-05-29 18:36 211 查看

usage

split(x, f, drop = false,...)


arguments

x: data to be divided

f: define the grouping

example 1

> split(1:10, 2)
$`2`
[1]  1  2  3  4  5  6  7  8  9 10

> split(1:10,1:2)
$`1`
[1] 1 3 5 7 9

$`2`
[1]  2  4  6  8 10


example 2

> split(sample(1:20),rep(1:10, length = 20))
$`1`
[1] 11  1

$`2`
[1] 20  5

$`3`
[1]  3 18

$`4`
[1] 17  9

$`5`
[1] 13  8

$`6`
[1]  4 14

$`7`
[1] 12  2

$`8`
[1] 15 19

$`9`
[1] 10  6

$`10`
[1]  7 16


where

> sample(1:20)
[1] 20  2 17  9 16  5  8 13  6  4  7  3 14 19 11 12 15  1 18 10
> rep(1:10, length = 20)
[1]  1  2  3  4  5  6  7  8  9 10  1  2  3  4  5  6  7  8  9 10


reflection

For the case split(1:10, 1:10), it means split the number 1 to 10 into 10 groups.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  r语言