While I can read R
, I can't write it (I don't have it installed, so can't test). I will give you a simple example in Matlab that will do something like what you asked - I hope this inspires you:
obs = sort([10 11 12 13 13 13 13 14 15 50]); % have to make sure they are sorted...
uo = unique(obs);
hh = hist(obs, uo); % find frequencies of each value
cpdf = cumsum(obs);
cpdfn = cpdf / max(cpdf); % normalized cumulative pdf
r = rand(1, 100); % 100 random numbers from 0 to 1
rv = round(interp1(cpdfn, uo, r)); % randomly pick values in the cpdfn; find corresponding "observation"
hr = hist(rv, 1:50);
hrc = cumsum(hr);
figure
plot(uo, cpdfn);
hold all;
plot(1:50, hhc/max(hhc))
figure; hist(rv, 1:50);
This produces the following plots:
Note - this works better as you have more observations; with the current example, because you have relatively few samples, the space between 15 and 50 gets sampled about 10% of the time.