[R] Sampling dataframe

Ronaldo Reis Júnior chrysopa at gmail.com
Wed Nov 25 19:23:58 CET 2009


Hi,

I have a table like that:

> datatest     
   var1 var2 var3
1     1    1    1
2     3    1    2
3     8    1    3
4     6    1    4
5    10    1    5
6     2    2    1
7     4    2    2
8     6    2    3
9     8    2    4
10   10    2    5

I need to create another table based on that with the rules:

take a random sample by var2==1 (2 sample rows for example):

   var1 var2 var3
1     1    1    1
4     6    1    4

in this random sample a get the 1 and 4 value on the var3, now I need to 
complete the table with var1==2 with the lines that var3 are not select on 
var2==1

The resulting table is:
   var1 var2 var3
1     1    1    1
4     6    1    4
7     4    2    2
8     6    2    3
10   10    2    5

the value 1 and 4 on var3 is not present in the var2==2.

I try several options but without success. take a random value is easy, but I 
cant select the others value excluding the random selected values.

Any help?

Thanks
Ronaldo


-- 
17ª lei - Seu orientador quer que você se torne famoso, 
          de modo que ele possa, finalmente, se tornar famoso.

      --Herman, I. P. 2007. Following the law. NATURE, Vol 445, p. 228.
--
> Prof. Ronaldo Reis Júnior
|  .''`. UNIMONTES/DBG/Lab. Ecologia Comportamental e Computacional
| : :'  : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia
| `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil
|   `- Fone: (38) 3229-8192 | ronaldo.reis at unimontes.br | chrysopa at gmail.com
| http://www.ppgcb.unimontes.br/lecc | ICQ#: 5692561 | LinuxUser#: 205366
--
Favor NÃO ENVIAR arquivos do Word ou Powerpoint
Prefira enviar em PDF, Texto, OpenOffice (ODF), HTML, or RTF.




More information about the R-help mailing list