So, I have a vector, points
, that I want to populate with a pair of points, whose x and y coordinates are uniformly distributed between 0 and 1.
Here is my code so far:
n <- 10000
points <- rep(0, n)
for (i in 1:n) {
a <- list(x=runif(1, 0, 1), y=runif(1, 0, 1))
b <- list(x=runif(1, 0, 1), y=runif(1, 0, 1))
replace(points, i, list(a, b))
}
I have tried the following:
n <- 10000
points <- rep(0, n)
for (i in 1:n) {
a <- list(x=runif(1, 0, 1), y=runif(1, 0, 1))
b <- list(x=runif(1, 0, 1), y=runif(1, 0, 1))
points[i] <- list(a, b)
}
As you can see, a
is the first point with uniformly distributed x and y, and b
is the second point with uniformly distributed x and y. For each i
in 1:n
, I'm trying to replace the i
th element in points
with list(a, b)
; however, I keep on getting the warning "number of items to replace is not a multiple of replacement length", indicating that it's trying to replace the i
th element in points
with a
and b
as separate elements, and not replacing it with a single list
element containing a
and b
. Is there any way I can coax it to do what I want?