***~会飞的蝎子~学习宁静致远 » 日志 » some useful statement
some useful statement
蝎子 发表于 2008-05-08 05:11:29
Use R statement~~~In terms of HW, how to mark the vector has all the integer from 2 to 12, there is some built-in functions can perform better than program directly... Here are 2 methods to identify the result:
Method1:
use is.element
e.g.:
> x=as.integer(10*runif(10))+1
> x
[1] 7 7 4 9 2 2 7 5 6 3
> sum(is.element(c(2:12),x))
[1] 7
# is ==11, means all 2:12 are included
Method2:
use unique()
e.g.:
> x=as.integer(10*runif(10))+1
> x
[1] 3 5 7 6 10 9 3 8 8 7
> unique(x)
[1] 3 5 7 6 10 9 8
> length(unique(x))
[1] 7
# if length ()==11, means, All 2:12 are in x.
Method1:
use is.element
e.g.:
> x=as.integer(10*runif(10))+1
> x
[1] 7 7 4 9 2 2 7 5 6 3
> sum(is.element(c(2:12),x))
[1] 7
# is ==11, means all 2:12 are included
Method2:
use unique()
e.g.:
> x=as.integer(10*runif(10))+1
> x
[1] 3 5 7 6 10 9 3 8 8 7
> unique(x)
[1] 3 5 7 6 10 9 8
> length(unique(x))
[1] 7
# if length ()==11, means, All 2:12 are in x.
相关日志:
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾

