choosing one pair randomly from repeated pairs I have two vectors, in my case all states in the US, and another vector, which indicates the states that it borders. States in vector 1 repeat for each state it borders. For instance, there would be 3 observations for California: California-Nevada; California-Oregon; California-Arizona. 
For each state, I would like to randomly choose one of these dyads and create a new dataset. Let's say the original data set was 300 x 2. The new dataset would be 50x2. Here is an example dataset. 
state <- sample(state.abb,size=300,replace=T)
neighbor <- sample(state.abb,size=300,replace=T)
data <- data.frame(state,neighbor)

thanks!
 A: There are (of course) any number of ways to do this.  The approach I apply here uses data.table and does what is desired in a single line of code that is readable if you are familiar with data.table.
library(data.table)
result <- data.table(data)[,.SD[sample(1:.N,1),],by="state",]

In short, we convert data into a data.table.  Using the nomenclature data.table(data)[i,j]...
We are processing data by subsets of each unique value for state (the by argument), as if we used state== for each unique value of state in position of the argument i (row selection).  
The j argument (results) provides the output from each subset.  Here we want a random row from each subset of data.  Each individual subset is internally referred to as .SD in the position of j.  So, we can just randomly sample a row from that subset ([sample(1:.N,1),]) in the i (row selection arguement) where .N is internally defined for a data.table (in this case .SD, because this is a bracketed selection from .SD) as the number of rows in that data.table.
