I have a column in a data frame that looks something like this:
[1] [0.50 .. 0.52] [0.52 .. 0.54] [0.54 .. 0.56] [0.56 .. 0.58]
[5] [0.58 .. 0.60] [0.60 .. 0.62] [0.62 .. 0.64] [0.64 .. 0.66]
[9] [0.66 .. 0.68] [0.68 .. 0.70] [0.70 .. 0.72] [0.72 .. 0.74]
[13] [0.74 .. 0.76] [0.76 .. 0.78] [0.78 .. 0.80] [0.80 .. 0.82]
I would like to take the average of the two numbers in this column. However, I don’t know how to go about this. I tried using gsub() to replace the ” .. ” but I cannot remove the brackets, and I cannot seem to find a way to just extract the numbers. What would be the best way to just get the average of these numbers?
Use
gsubto take out the brackets (remembering to double escape for them), then usestrsplitto separate the numbers, andsapplyto work on the resulting list withmeanandas.numeric: