楼主: muyangren001
8580 3

[问答] R语言中怎么定义只有0和1的向量啊? [推广有奖]

  • 0关注
  • 1粉丝

高中生

40%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
138 点
帖子
11
精华
0
在线时间
35 小时
注册时间
2014-3-26
最后登录
2020-3-10

楼主
muyangren001 发表于 2014-3-26 18:01:03 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
求高人指点一二,定义一个七维的由0和1组成的向量……
刚接触R,比较着急
感谢
二维码

扫码加我 拉你入群

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

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

关键词:R语言 求高人指点 高人指点

沙发
danica33 发表于 2014-3-26 22:42:57
vec<-rbinom(7,1,0.5)
或者,
vec<-sample(c(0,1),7,replace=T)

藤椅
muyangren001 发表于 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))

板凳
liugongqin 发表于 2021-11-2 14:50:18
提示: 作者被禁止或删除 内容自动屏蔽

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-8 06:47