Tuesday, July 12, 2016

changing table demo in R

tb = data.frame(matrix(, nrow=1, ncol=3)) #set up a skeleton table
names(tb) = c('x', 'y', 'z')
for( seed in c(12345, 20160711, -1881, 9999.1234)) {
  set.seed(seed);
  x = rnorm(1)
  y = runif(1)
  z = rbinom(1, 1, 0.5)
  tb = rbind(tb, c(x, y, z))  
}
tb= tb[!is.na(tb[,1]), ]
tb
##            x         y z
## 2  0.5855288 0.7609823 1
## 3 -1.0876501 0.7777066 1
## 4 -0.4376543 0.9012065 0
## 5  1.0840991 0.8004162 0

No comments:

Post a Comment