I found this code through internet and I have a one doubt about this example, 
which is
Here you take a 70% random sample considering all the values but what I want is 
if the selected sample contains p1,p2 then I want all records of p1,p2 and also 
remaining data in some other data frame...like following output

D1

V1  v2
P1  10
P1  3
P1  4
P1  2
P2  30
P2  40

D2

V1  v2
P3  4
P3  1

I hope you understood my doubt.............please help me

Thanks,
Madhu.





> read.table(textConnection(gsub("\\(|\\)", "", var) ))  #from prior
posting
   V1 V2
1 p1 10
2 p1  3
3 p1  4
4 p2 20
5 p2 30
6 p2 40
7 p3  4
8 p3  1
9 p1  2

> ridxs <- sample(1:nrow(df),floor(0.7*nrow(df)) )  # the 70% sample
row IDs

> df[ridxs,]
   V1 V2
5 p2 30
6 p2 40
2 p1  3
7 p3  4
4 p2 20
8 p3  1
>
>
> df[-ridxs,]
  V1 V2
1 p1 10
3 p1  4
9 p1  2


        [[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.

Reply via email to