Displaying 5 results from an estimated 5 matches for "sampleno".
2017 Sep 25
2
Sample of a subsample
Hello everybody!
I have the following problem: I'd like to select a sample from a subsample
in a dataset. Actually, I don't want to select it, but to create a new
variable sampleNo that indicates to which sample (one or two) a case
belongs to.
Lets suppose I have a dataset containing 40 cases:
data <- data.frame(var1=seq(1:40), var2=seq(40,1))
The first sample (n=10) I drew like this:
data$sampleNo <- 0
idx <- sample(seq(1,nrow(data)), size=10, replace=F)
data[id...
2017 Sep 25
1
Sample of a subsample
...is comment to use the name 'dat' rather than 'data' is instructive.
I am providing my suggestion as well because I think it may address
what was causing you some confusion (mainly to use "which", but also
the missing !)
idx2 <- sample( which( (!data$var1%%2) & data$sampleNo==0 ), size=10,
replace=F)
data[idx2,]$sampleNo <- 2
Eric
On Mon, Sep 25, 2017 at 9:03 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
> For personal aesthetic reasons, I changed the name "data" to "dat".
>
> Your code, with a slight modification:
>
&...
2017 Sep 25
0
Sample of a subsample
For personal aesthetic reasons, I changed the name "data" to "dat".
Your code, with a slight modification:
set.seed (1357) ## for reproducibility
dat <- data.frame(var1=seq(1:40), var2=seq(40,1))
dat$sampleNo <- 0
idx <- sample(seq(1,nrow(dat)), size=10, replace=F)
dat[idx,"sampleNo"] <-1
## yielding
> dat
var1 var2 sampleNo
1 1 40 0
2 2 39 1
3 3 38 0
4 4 37 0
5 5 36 0
6 6 35 1
7 7 34 0...
2006 Oct 17
2
Calculate NAs from known data: how to?
Hi
In a dataset I have length and age for cod. The age, however, is ony
given for 40-100% of the fish. What I need to do is to fill inn the NAs
in a correct way, so that age has a value for each length. This is to be
done for each sample seperately (there are 324 samples), meaning the NAs
for sampleno 1 shall be calculated from the known values from sampleno 1.
As for example length 55 cm can be both 4 and 5 years, I guess a fish
with NA age and length 55 cm should be given a "random" age given a
probability for example "55 cm = 4 years has a p=75%, while 55 cm = 4
years has a...
2006 Apr 10
1
Generic code for simulating from a distribution.
...a
particular distribution (here,beta distribution) and compute some
statistics for the samples.
betasim2<-function(nsim,n,alpha,beta)
{
sim<-matrix(rbeta(nsim*n,alpha,beta),ncol=n)
xmean<-apply(sim,1,mean)
xvar<-apply(sim,1,var)
xmedian<-apply(sim,1,median)
simset<-data.frame(sampleno=seq1:nsim),means=xmean,vars=xvar,medians=xmedian)
return(simset)
}
I can write a similar coding for any distribution individually.
Now, I would like to have a generic code, say if I specify the
distribution with the parameters and simulation and sample size I would
like to have the simulations do...