出于测试目的,我需要向没有缺失值的数据帧添加缺失值,如何向我的数据帧添加10%的随机NA:
dat <- data.frame(v1=rnorm(20),v2=rnorm(20),v3=rnorm(20))
我的想法是这样的:
a <- sample(1:nrow(dat),3,replace=F)
b <- sample(1:ncol(dat),2,replace=F)
dat[a,b] <- NA
但这还不够随机。谢谢。
是否可能从控制器中的操作中获取集合的shuffle/random。
def action
#pseudocode something like the next:
@objects = Object.random
respond_to do |format|
format.html
end
end
我现在可以从我的观点中得到洗牌,包括:
<% @objects.shuffle.each do |microfunc| %>
.
.
.
<% end %>
使用each or for loop是可以查看的。我不希望使用循环从一个集合中获取随机对象。
如何从我的操
我是个新手,如果我犯了什么新手错误,请耐心点。我正在尝试写一个数据库,并从数据库中返回一个随机条目。该程序应启动一个随机化活动,该活动将在按下随机化按钮时更新文本视图。\ public void (视图v) { view.setText(randRecipe());}
public String randRecipe()
{
Random rand= new Random();
int r= rand.nextInt(base.size());
Recipe rec= base.get(r);
return rec.toString();
我使用python在用户的两个值之间随机生成整数,我的代码如下所示。我正在犯错误:
from random import *
i1 = input('Enter the N1 :')
i2 = input('Enter the N2 :')
r = randint({0},{1}.format(i1,i2))
print r
这里我从用户那里获取i1和i2,并希望在i1和i2之间生成随机整数。
我发现了一个错误:
File "index.py", line 6
r = randint({0},{1}.format(i1,i2))
想知道我到底做错了什么。我试图将一个整数传递给我的自定义类,当我输出时,函数中的参数是某个随机数,而不是我传递的值。下面是我在RootViewController.m中的方法调用:
int orgID = organObj.organID;
NSLog(@"OrganID from RVC: %d", orgID); // this outputs the correct number
[Procedure getDatabase:[appDelegate getDBPath] WithOrganID:[NSNumber numberWithInt:orgID]];
我必须根据时间、计数器和从1到10的随机预设值来生成唯一的ID。我生成它的方式:
$time = (int)(time()+$i);
$time = $time.(rand(1,9));
//At this step we have strings looking like this:
"13480835672" //This is time in first iteration
"13480835672" //This is time in second iteration
//But if I convert it to int
$time = (int)