全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
8469 3
2014-03-26
求高人指点一二,定义一个七维的由0和1组成的向量……
刚接触R,比较着急
感谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-3-26 22:42:57
vec<-rbinom(7,1,0.5)
或者,
vec<-sample(c(0,1),7,replace=T)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-4-4 21:23:49
非常感谢!!可是……能不能帮看下原题呀,主要是编个函数:
Function name: SHIFT
Inputs: a vector of size 7 (numbers)
Outputs: A random number.
How?
Shift Register generators are an example of a random number generator. The steps of the method are as follows:
i) Choose a binary seed. seed=(1,0,0,1,1,0,1)
ii) Shift the seed to the right 2 bits. seed=(0,0,1,0,0,1,1)
iii) Perform an exclusive-or addition of lines i and ii. seed=(1,0,1,1,1,1,0)
iv) Shift the sum to the left 3 bits. seed=(1,1,1,0,0,0,0)
v) Perform an exclusive-or addition of lines iii and iv. seed=(0,1,0,1,1,1,0)
vi) The answer is: 0*2^0+1*2+0*2^2+1*2^4+1*2^5+0*2^6=58
Your code should look like:
SHIFT=function(seed)
{
...lines of code...
return(_something to output_)
}
SHIFT=(c(0,1,1,0,1,1,0))
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2021-11-2 14:50:18
提示: 作者被禁止或删除 内容自动屏蔽
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群