You need to wrap it accordingly:
s1 <- cc[strata(cc, stratanames="ID", size=rep(1, 20),
method="srswr")$ID_unit, ]
Uwe
Krystyna Golabek wrote:
Thanks Uwe,
Your strata suggestion works, thank you, but it has created a dataset of random
rows but without the data, other columns involved. You see I would further like
to use this random sample for a DFA (lda) analysis. Can you suggest how I would
use the strata function to sample a subset of the data.frame?
Thanks
Krystyna
Date: Tue, 28 Apr 2009 14:33:22 +0200
From: lig...@statistik.tu-dortmund.de
To: kagola...@hotmail.com
CC: r-help@r-project.org
Subject: Re: [R] Random Sample with Unique function
In order to use stratified sampling, either try to implement it yourself
or use the "sampling" package and its function strata() as in:
s1 <- strata(cc, stratanames="ID", size=rep(1, 20), method="srswr")
>>
then you will get 1 observation for each ID. Note that it is not
important to use "with replacement" in your case, since you only sample
1 obervation for each stratum.
Uwe Ligges
Krystyna Golabek wrote:
Dear R-users
I have a dataset of 243 lines with replicate information for 20 different individuals (ID).
I would like to randomly sample this dataset 100 times with a selection of unique IDs in each sample.
First to create a random sample I have;
cc<-read.table(blah.blah.blah)
names(cc)
[1] "CALL" "CONTEXT" "ORDER" "ID" "STATUS"
s1<-cc[sample(1:243,20,replace=TRUE),]
This code samples 20 rows from the dataset but can anyone help me write the
code to request unique(ID) in this sample?
Thank you so much for your time and help.
Krystyna Golabek
_________________________________________________________________
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
_________________________________________________________________
Share your photos with Windows Live Photos – Free.
http://clk.atdmt.com/UKM/go/134665338/direct/01/
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.