[R] Reconstruct a dataset

Lisa lisajca at gmail.com
Wed Dec 16 00:10:24 CET 2009


Supplement to my problem

I know how to generate the random numbers, but I am not sure how to rewrite
the dataset. In my example, for the first set of random number, rn1 <- c(0,
0, 1, 1),  only the last two numbers are “1”s, not zeros, so I select the
individual 3 and individual 4 from y original dataset, i.e., 

2  1
2  2  

And then write these two rows as

id  var1.1  var1.2  var2.1  var2.2  
1        2       2       1       2  

For the second set of random number, rn2 <- c(0, 0, 2, 0), only the third
number is “2”,  so I select the individual 3 two times from my original
dataset, i.e., 

2  1
2  1  

And then write these two rows as

id  var1.1  var1.2  var2.1  var2.2  
2        2       2       1       1  

And so on.

Finally, combine all rows together

id  var1.1  var1.2  var2.1  var2.2  
1        2       2       1       2  
2        2       2       1       1  
….

Lisa

Lisa wrote:
> 
> Dear all,
> 
> I have a dataset that looks like this:
> 
> inividual   var1  var2   …
> 1              1     1   …
> 2              1     2   …  
> 3              2     1   …  
> 4              2     2   …  
> …              …     …   …
> 
> I will random sample 2 individuals from this dataset based on a set of
> random numbers, e.g., 
> 
> rn1 <- c(0, 0, 1, 1),  rn2 <- c(0, 0, 2, 0), rn3 <- c(1, 0, 0, 1), rn4 <-
> c(0, 1, 1, 0),…
> 
> After reconstructed the samples, I have a dataset that looks like this:
> 
> id  var1.1  var1.2  var2.1  var2.2  …
> 1        2       2       1       2  …
> 2        2       2       1       1  … 
> 3        1       2       1       2  … 
> 4        1       2       2       1  … 
> …        …       …       …       …  …
> 
> Please ignore the bold and italic fond styles, I just want to make my
> problem clear.
> 
> Can anyone please help how to get this done? Your help would be greatly
> appreciated. 
> 
> Lisa 
> 
> 
> 

-- 
View this message in context: http://n4.nabble.com/Reconstruct-a-dataset-tp964699p964761.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list