Q:

R Sample selection basic question with nrow

I follow one tutorial to split ds into several with sample and it works fine. I just can't sleep without  understaning what is going on behind the scene with ind dataset like in sample below, does it know/remember about mtcars somehow, it's just single column integer.  I indicated in comment what I'm trying to get, how R knows which row in dataset marked 1 or 2 ??
Yes I did my Hwork on basic syntax but this probably is too simple)
ind <- sample(2,nrow(mtcars), replace= T, prob = c(0.8,0.2))
ind
tdata <- mtcars[ind==1,]  # select rows where ind = 1 ??!! but we don't have ind column in mtcars???
vdata <- mtcars[ind==2,]

Updated with my interpretation after help from Adam.

ind  -- independent stand alone ds with single column int. No any logical relationship to mtcars. I tested this creating it manually and it works OK.
then it works with logical vector, matching rownum from mtcars to ind. Something like: let check row #1 from mtcars matching (by rownum)  row #1 from ind has value 1 so ind==1 translated to True and raw selected.

Please correct me if I'm wrong. 

A:

(1) This statement is saying the following: "Randomly sample the numbers 1 and 2 for a total number of how many rows there are in mtcars (32) with replacement, and make is such that a 1 has an 80% chance of being selected and a 2 has a 20% chance of being selected.
ind <- sample(2,nrow(mtcars), replace= T, prob = c(0.8,0.2))

(2) This line of code is subsetting mtcars to only those rows where your vector (ind) is a 1. The code ind==1 is creating a logical vector (i.e., full of TRUE and FALSE) values. Wherever there is a 1, ind==1 will be TRUE, otherwise it will be FALSE.
tdata <- mtcars[ind==1,]

(3) This line of code is essentially doing the same thing as step 2, but for wherever there is a 2 in ind.
vdata <- mtcars[ind==2,]

