I have a vector of r values ββas follows:
r<-c(1,3,4,6,7)
and a df data frame with 20 records and two columns:
id<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,1,4,15,16,17,18,19,20) freq<-c(1,3,2,4,5,6,6,7,8,3,3,1,6,9,9,1,1,4,3,7,7) df<-data.frame(id,freq)
Using the vector r , I need to extract a sample of records (in the form of a new data frame) from df so that the freq values ββof the records are equal to the values. I have a vector r . Needless to say, if he finds several records with the same freq values, he should randomly select one of them. For example, one possible result could be:
id frequency 12 1 10 3 4 4 7 6 8 7
I would appreciate it if someone could help me with this.