All the acrobatics with vectors of indices are unnecessary.
Logical indexing, subsetting are really all you need, using a new 'country' field (factor) you add to your data. (Maybe also plyr::ddply if you get real fancy)
All you want to do is allow the user to:
- Choose a country from a list (by selecting its number, 2-letter abbrev, whatever)...
- ... then sample in your dataset from within that country. That's all!
.
dat$country <- NA # insert a new column, initialize to NA for pessimism, to catch omissions
dat$country[1:1043,] <- 'Belgium'
dat$country[2044:3061,] <- 'Bulgaria'
dat$country[8423,8922,] <- 'Czech Rep'
...
# Now make country a factor instead of character
dat$country <- as.factor(dat$country)
# Now you can sample() using either logical indexing...
sample(dat[dat$country=='Bulgaria',] , ...)
# ...or subsetting
sample(subset(dat,country=='Bulgaria'), ...)