Hi,
May be this helps:
set.seed(42)
indx <- with(df,tapply(seq_along(IndividualID), FamilyID,FUN=sample,1))
df[indx,]
# FamilyID IndividualID DadID MomID Sex
#4 1 104 0 0 2
#8 2 204 202 203 2
#or
library(plyr)
ddply(df,.(FamilyID),function(x) x[w
2014 10:11 a.m.
To: r-help@r-project.org
Subject: [R] Select random observation from a group
Hello,
I have a dataset with family data. For an analysis, I need to select one
subject per family at random.
Here is an example of what my data look like:
FamilyID IndividualID DadID
Hello,
I have a dataset with family data. For an analysis, I need to select one
subject per family at random.
Here is an example of what my data look like:
FamilyID IndividualID DadIDMomID Sex
1101103 104 1
1
3 matches
Mail list logo