I have a table which has an elasticity column. To each of the records, I want to assign a new elasticity value. That value is based on performing a sampling assuming uniform distribution. For eg, lets say I have 4 records with elasticity values (1.2, 1.3, 1.4, 1.5). So I take a sample of these 4 values 50 times, after which I have a matrix of 4X50. How do I assign the value that came up the most to the record?
num_vals_to_sample = sum(measurement_Elasticity); #Counts the no of records
Sampled_measurement_Elasticity = replicate(50, sample(measurement_Elasticity, num_vals_to_sample, replace = TRUE))
In the above code, I want a new measurement_Elasticity vector which has the value that came up the most during the sampling process.
Using Henry's code, I solved my problem this way:
num_vals_to_sample = sum(measurement_Elasticity);
New_measurement_Elasticity = c()
#Elasticity Sampling
for (i in 1:num_vals_to_sample)
{
Sampled_measurement_Elasticity <- table(sample(measurement_Elasticity), 100, replace=TRUE))
Most_Likely_Elas =as.numeric(names(Sampled_measurement_Elasticity)[max(which(Sampled_measurement_Elasticity==max(Sampled_measurement_Elasticity)))])
append(New_measurement_Elasticity, Most_Likely_Elas)
}