One method for generating uniformly distributed coordinates in a data frame for a specified number of points is to use the runif() function to generate random numbers for the x and y coordinates, and then combine them into a data frame. For example:
# set number of points
n_points <- 100
# generate uniformly distributed x and y coordinates
x_coords <- runif(n_points, min = 0, max = 1)
y_coords <- runif(n_points, min = 0, max = 1)
# combine coordinates into a data frame
df <- data.frame(x = x_coords, y = y_coords)
This will generate a data frame with n_points rows, where each row has a randomly generated x and y coordinate that is uniformly distributed between 0 and 1. The min and max arguments of the runif() function can be adjusted to change the range of the uniform distribution.
Asked: 2023-04-30 00:26:20 +0000
Seen: 9 times
Last updated: Apr 30 '23