您的位置:首页 > 产品设计 > UI/UE

swirl 3: Sequences of Numbers

2015-08-06 18:09 393 查看
> pi:10
[1] 3.141593 4.141593 5.141593 6.141593 7.141593 8.141593 9.141593

不同于 MATLAB,a:b,a\b均可以不是整数。

> 15:1

 [1] 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1

可以倒着来

| Remember that if you have questions about a particular R function, you can access its documentation with a question mark followed

| by the function name: ?function_name_here. However, in the case of an operator like the colon used above, you must enclose the

| symbol in backticks like this: ?`:`

operator查询,?':'(密切注意中英文符号)

> seq(0, 10, by=0.5)

 [1]  0.0  0.5  1.0  1.5  2.0  2.5  3.0  3.5  4.0  4.5  5.0  5.5  6.0  6.5  7.0  7.5  8.0  8.5  9.0  9.5 10.0

> seq(5, 10, length=30)

 [1]  5.000000  5.172414  5.344828  5.517241  5.689655  5.862069  6.034483  6.206897  6.379310  6.551724  6.724138  6.896552  7.068966

[14]  7.241379  7.413793  7.586207  7.758621  7.931034  8.103448  8.275862  8.448276  8.620690  8.793103  8.965517  9.137931  9.310345

[27]  9.482759  9.655172  9.827586 10.000000

> 1:length(my_seq)

 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

operator前后可以跟函数返回值

> seq(along.with = my_seq)

 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

seq的argument真多啊,活学活用。

> seq_along(my_seq)

 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

seq(along.with = my_seq) == seq_along(my_seq)

> rep(c(0, 1, 2), times = 10)

 [1] 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2

rep stands for "replicate".

> rep(c(0, 1, 2), each = 10)

 [1] 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2

rep argument 也很多啊。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: