Displaying 1 result from an estimated 1 matches for "ntarget".
Did you mean:
target
2008 Jun 11
3
searching for specific row in matrix
...data
create_bin_string <- function(len)
{
sample(0:1, len, replace=T)
}
ROWS = 10
COLS = 5
pop = matrix(create_bin_string(ROWS*COLS), ROWS, COLS, byrow=T)
target=c(1, 1, 0, 1, 1)
# my population
print(pop)
# I am looking for the index of this in pop
# if present (else -1?)
cat("\ntarget: ", target, "\n")
##
## this is NOT working
## plus it would continue to search
## after it found the target
##
for(i in ROWS)
if (pop[i,] == target)
cat("\nfound in row: ", i, "\n\n")