How to subset inside for loop using two dataframes?

I have two data frames, DS and MS. I am trying to match subjects in DS with a variable called 'period' from MS. Based on the dates in DS, if a date (in DS) falls between msfirstdate and mslastdate (in MS) then I assign the corresponding period value.

Below is 'MS',

subjectid msfirstdate  mslastdate   period
1         2020-07-10   2020-07-17      1
1         2020-07-17   2020-07-22      2
1         2020-07-22   2020-07-27      3
2         2020-07-19   2020-07-24      1
2         2020-07-24   2020-07-27      2
2         2020-07-27   2020-07-30      3
3         2020-07-11   2020-07-18      1
3         2020-07-18   2020-07-23      2
... and so on

*Number of period is different for each subject. One can have up to 8 periods for example (so 8 rows for that subject) *ms last date is inclusive and ms first date is non-inclusive

Below is DS,

subjectid dsdate 
1         2020-07-16
1         2020-07-17
1         2020-07-18
1         2020-07-19
1         2020-07-20
1         2020-07-21
2         2020-07-22
2         2020-07-23
2         2020-07-24
2         2020-07-25
2         2020-07-26
2         2020-07-27
...so on

What I want at the end is :

subjectid dsdate       Period
1         2020-07-16.    1
1         2020-07-17.    2
1         2020-07-18.    2
1         2020-07-19.    2
1         2020-07-24.    3
1         2020-07-25.    3
2         2020-07-22.    1
2         2020-07-23.    1
2         2020-07-24.    2
2         2020-07-25.    2
2         2020-07-26.    2
2         2020-07-27.    3
...

So I am trying for loop as i have more than 5000 rows in DS.

for (i in 1:nrow(DS) ) {
day_i <- DS[i,'dsdate'] 
dsid <- DS[i,'subjectid']  
MS2 <- subset(MS, subjectid == dsid & msfirstdate <= day_i & 
            mslastdate >= day_i )
DS[i,"period"]<- MS2$period
}

However, the MS2 results in 0 observations.. what I am doing wrong here? Thank you in advance!