R - Determining all combinations of profiles (four categories) matching predefined criteria

Viewed 38

I have a population categorized based on four caracteristics: gender (female, male), age (young, middle-aged, old), geography (urban, rural) and education (lower, higher).

This leaves me with 24 possible combinations:

[1]   Female  Young  Urban  Lower
[2]   Female  Young  Urban  Higher
[3]   Female  Young  Rural  Lower
[4]   Female  Young  Rural  Higher
...
[24]  Male    Old    Rural  Higher

Let's say I want to draw a stratified sample of 25 people, among which:

Female:      13
Male:        12
---------------
Young:        7
Middle-aged:  8
Old:         10
---------------
Urban:       15
Rural:       10
---------------
Lower:       20
Higher:       5

In order to do so, I want to determine which combinations of the profiles above will allow me to achieve this distribution (e.g. 2x[1], 3x[2], 1x[3] ... 2x[24]), using R.

I thought I could (i) create a dataset with my 24 combinations having value 1-3 (using the crossing() function), (ii) calculate the products and (iii) check if they match my distribution. However, I do not even manage to create the base dataset because it is too large for my memory (3^24 = 282429536481)...

Is there someone who could help me to achieve this in an easier way (with a loop function maybe, that checks if a combination matches and drops it immediately if it does not, in order to save memory; or just a mutch easier way I did not think of)?

Many thanks in advance.

0 Answers
Related