Skip to content

Commit fba688d

Browse files
committed
wrapped up saving random sample matrix for alternative choice matrix
1 parent 0720b3a commit fba688d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

R/create_alternative_choice.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,13 @@ create_alternative_choice <-
366366
}
367367

368368
# Grid-sampling ----
369+
# TODO - as we build additional options for grid sampling we will want to move this code to its own function
369370
if(grid_sample){
370371
# Create a matrix with nrows = observations, and columns = alts. The first column = choice.
371372
rand_alts_mat <- matrix(choice, nrow = length(choice), ncol = 1)
372373

373374
draw_alts <- function(choice, all_alts, numAlts){
374-
c(choice, sample(all_alts[all_alts != choice], numAlts))
375+
c(choice, sample(all_alts[!(all_alts %in% choice)], numAlts))
375376
}
376377

377378
rand_alts_mat <- do.call(rbind, lapply(rand_alts_mat, draw_alts, all_alts = zone_cent$ZoneID, numAlts = grid_sample_n))
@@ -403,8 +404,7 @@ create_alternative_choice <-
403404
spatname = spat,
404405
grid_sample = grid_sample,
405406
grid_sample_n = grid_sample_n,
406-
rand_alts_mat = rand_alts_mat
407-
)
407+
rand_alts_mat = rand_alts_mat)
408408

409409
# write Alt to datafile ----
410410
# Save table names

0 commit comments

Comments
 (0)