I couldn't figure out a quick way to import the data how you had your paste formatted (with curly brackets for each element, but no outer curly brackets) so I reformatted it and repasted it.
data = Import["http://pastebin.com/raw/V8807EsY", "Table"];
You say you'd like to average the duplicate points, so using Mean
in combination with GatherBy
should work,
interp = Interpolation[Mean /@ GatherBy[data, First]]
Interpolation::inddp: The point 0.9216985231092443` in dimension 1 is duplicated. >>
but it doesn't since you have so many digits in your numbers. By this, I mean that the difference between the two x-values in question (0.9216985231092445 and 0.9216985231092443) is equal to $MachineEpsilon
. This is an easy workaround,
interp = Interpolation[
Mean /@ GatherBy[data, Round[First[#], 10^-14] &]]
Show[
Plot[interp[x], {x, 0.4, 14}, Axes -> False, Frame -> True],
ListPlot[data, PlotStyle -> Red]
]
A longer, easier to read version of the code above is
interp = Interpolation[
Map[Mean,
GatherBy[data,
Function[x, Round[First[x], 10^-14]]
]
]
]
The base command is GatherBy
which applies the function given to each element of the list, and sorts those which give the same result into sublists. So any element of your list who would give the same result when you take its first element and round it to 0.00000000000001 is then grouped together in a sublist. The result of GatherBy
is then a list of lists. Now you can just Map
the function Mean
onto each of these sublists (taking the average of their x and y values).