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.
关键词(Tag): 213 user biostat

曾经的这一天...

相关日志:

收藏: QQ书签 del.icio.us 订阅: Google 抓虾

最新评论


  • ming
    2008-05-08 07:02:19 匿名 164.67.*.*

    good to know. very useful! thanks a million:)



    :) haha

发表评论

* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 
 

分类小组论坛
杂谈, 娱乐、八卦, 文学、艺术, 体育, 旅游、同城, 象牙塔, 情感, 时尚、生活, 星座, 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定