Hi:
Here's a slightly different approach, using both mapply() in base (a la
David) and mlply() in plyr.
My thought was to put the arguments together into a three column data frame;
the names were chosen to correspond to the first three arguments of runif():
params <- data.frame(n = as.vector(rat
Sarah,
Here's a version using two nested loops:
rate_number = matrix(c(5, 15, 60, 15, 5, 0, 20, 60, 20,0, 10, 20, 40,
20, 10), nrow = 5, ncol = 3)
range_mat = matrix(c(6.25, 6.75, 7.25, 8.75, 9.25, 9.75, 8.5, 9, 9.5,
10.5, 11, 11.5, 4.25, 4.75, 5.25, 5.75, 6.25, 6.75), nrow = 6, ncol = 3)
set.s
On Sep 3, 2010, at 6:32 AM, Sarah Sanchez wrote:
Dear R helpers
I have following dataset
rate_number = matrix(c(5, 15, 60, 15, 5, 0, 20, 60, 20,0, 10, 20,
40, 20, 10), nrow = 5, ncol = 3)
range_mat = matrix(c(6.25, 6.75, 7.25, 8.75, 9.25, 9.75, 8.5, 9,
9.5, 10.5, 11, 11.5, 4.25, 4.7
Try this:
> result <- list() # holds the numbers for each column
> for (i in seq(ncol(rate_number))){
+ ans <- NULL
+ for (j in seq(nrow(rate_number))){
+ ans <- c(ans, runif(rate_number[j, i], range_mat[j, i],
range_mat[j + 1, i]))
+ }
+ result[[i]] <- ans
+ }
> result
[[
Dear R helpers
I have following dataset
rate_number = matrix(c(5, 15, 60, 15, 5, 0, 20, 60, 20,0, 10, 20, 40, 20, 10),
nrow = 5, ncol = 3)
range_mat = matrix(c(6.25, 6.75, 7.25, 8.75, 9.25, 9.75, 8.5, 9, 9.5, 10.5, 11,
11.5, 4.25, 4.75, 5.25, 5.75, 6.25, 6.75), nrow = 6, ncol = 3)
> rate_
5 matches
Mail list logo