[R] Newb: How I find random vector index?

2013-10-17 Thread Stock Beaver
# Suppose I have a vector: myvec = c(1,0,3,0,77,9,0,1,2,0) # I want to randomly pick an element from myvec # where element == 0 # and print the value of the corresponding index. # So, for example I might randomly pick the 3rd 0 # and I would print the corresponding index # which is 7, # My

[R] A 'good' way to build a matrix from a sequence of integers?

2013-10-15 Thread Stock Beaver
# I understand that a good way to build a vector from a sequence of integers, # is to use syntax like this: myvec = c(1:99) # Here is the 'short' version of my question: # I want to understand a 'good' way to build a matrix from a sequence of integers. # If that question is not clear, here is a