【R语言学习】split函数

来源:互联网 发布:anywhere2 mac 驱动 编辑:程序博客网 时间:2024/05/04 16:49

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.

0 0
原创粉丝点击