[R] Randomly generating data

Lisa lisajca at gmail.com
Mon Mar 21 18:43:35 CET 2011


Hi, everybody,

I have a problem and need your help.
There are two columns that look like this:

 [1,] "t"  "f" 
 [2,] "f"  "t" 
 [3,] "t"  "f" 
 [4,] "t"  "t" 
 [5,] "f"  "f" 
 
I just want to generate the third column based on these two columns. First,
I randomly choose one of the two columns, say, the first column. So, the
first character of the third column is “t” that looks like this:

 [1,] "t"  "f"  "t"
 [2,] "f"  "t" 
 [3,] "t"  "f" 
 [4,] "t"  "t" 
 [5,] "f"  "f" 
 
Second, I determine the second character of the third column with an
additional Bernoulli trial with a probability, for example, rbinom(1, 1,
0.3). If the random generation in R is 0, we keep "f", the second character
in the first column because the first column has been chosen in the first
step, while if the random generation in R is 1, we choose "t" instead, the
second character in the second column.    

Third, I determine the third character of the third column with a Bernoulli
trial but a different probability, for example, rbinom(1, 1, 0.7). 

Repeat these processes…

How can I do this efficiently if there are more than thousand records
(rows)?  Can anybody please help how to get this done? Thanks a lot in
advance

Lisa



--
View this message in context: http://r.789695.n4.nabble.com/Randomly-generating-data-tp3394250p3394250.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list