data analysis

arun karkare

New Member
Joined
Oct 29, 2015
Messages
2
Hello experts;
I have a huge data, say 100000 values, each value between 0 to 255.
Values are in random order.
I first find the average of all values. by simply using the AVERAGE formula.
Next I find the values which are greater than average. Highlight them, using "Conditional formatting"
'Continuously' highlighted values are called sets.
Then I need to find 'number of values' in each set.
I also need to know 'average value' of each set.
Following example will clarify it further;
data:39,29,45,56,57,59,25,56,78,89,77,65,45,43,48,58,59,45,44,67...etc
overall average:54.2
more than avg:39,29,45,56,57,59,25,56,78,89,77,65,45,43,48,58,59,45,44,67......
number of values in sets:3, 5, 2, 1....
avg value in a set;57.3, 73, 58.5, 67.....
Questions:
what formula I should use to extract following information:
number of values in sets,
average values for the set.

Many Thanks in advance for ur support.
-arun karkare
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Welcome to the forum!
The code below can be used to analyze your data, assumed to be in column A starting in A1 as shown in the example. C1 is the average of all data points. Starting in C2 and down is the sequence: Count of successive values that exceed the overall average (values in a set), followed by the average of the values in the set. A test on 10,000 random values between 0 and 255 was analyzed in 0.9 seconds on a relatively old computer/processor. The data in the test contained 2497 sets.
Excel Workbook
ABC
13127.0981
21001
3218218
41137
5121219.7143
6961
763184
8983
985188.3333
101211
11194159
122212
13204172.5
142141
15245228
162524
17208205.75
181091
19102144
201021
21184168
22742
239166
24132
2529199.5
26813
2735193.3333
281793
29234199.6667
301522
Sheet1


Code:
Sub DataAnalysis()
Dim lR As Long, V As Variant, Avg As Double, ct As Long, Savg As Double
Dim n As Long, S As Double, ctS As Long
lR = Range("A" & Rows.Count).End(xlUp).Row
V = Range("A1:A" & lR).Value
Avg = WorksheetFunction.Average(Range("A1:A" & lR))
Application.ScreenUpdating = False
[C1] = Avg
n = 1
NextSet:
Do
       For i = n To UBound(V, 1)
              If V(i, 1) > Avg Then
                     ct = ct + 1
                     n = i + 1
                     S = S + V(i, 1)
              ElseIf ct = 0 Then
                     n = n + 1
                     GoTo NextSet
              Else
                     Exit Do
              End If
       Next i
Loop While n <= UBound(V, 1)
If ct > 0 Then
       ctS = ctS + 1
       lR = Range("C" & Rows.Count).End(xlUp).Row
       Cells(lR + 1, "C") = ct
       Cells(lR + 2, "C") = S / ct
       ct = 0
       S = 0
       If n < UBound(V, 1) Then GoTo NextSet
End If
MsgBox ctS & " sets analyzed"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Welcome to the forum!
The code below can be used to analyze your data, assumed to be in column A starting in A1 as shown in the example. C1 is the average of all data points. Starting in C2 and down is the sequence: Count of successive values that exceed the overall average (values in a set), followed by the average of the values in the set. A test on 10,000 random values between 0 and 255 was analyzed in 0.9 seconds on a relatively old computer/processor. The data in the test contained 2497 sets.
Sheet1

ABC
13127.0981
21001
3218218
41137
5121219.7143
6961
763184
8983
985188.3333
101211
11194159
122212
13204172.5
142141
15245228
162524
17208205.75
181091
19102144
201021
21184168
22742
239166
24132
2529199.5
26813
2735193.3333
281793
29234199.6667
301522

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4

Code:
Sub DataAnalysis()
Dim lR As Long, V As Variant, Avg As Double, ct As Long, Savg As Double
Dim n As Long, S As Double, ctS As Long
lR = Range("A" & Rows.Count).End(xlUp).Row
V = Range("A1:A" & lR).Value
Avg = WorksheetFunction.Average(Range("A1:A" & lR))
Application.ScreenUpdating = False
[C1] = Avg
n = 1
NextSet:
Do
       For i = n To UBound(V, 1)
              If V(i, 1) > Avg Then
                     ct = ct + 1
                     n = i + 1
                     S = S + V(i, 1)
              ElseIf ct = 0 Then
                     n = n + 1
                     GoTo NextSet
              Else
                     Exit Do
              End If
       Next i
Loop While n <= UBound(V, 1)
If ct > 0 Then
       ctS = ctS + 1
       lR = Range("C" & Rows.Count).End(xlUp).Row
       Cells(lR + 1, "C") = ct
       Cells(lR + 2, "C") = S / ct
       ct = 0
       S = 0
       If n < UBound(V, 1) Then GoTo NextSet
End If
MsgBox ctS & " sets analyzed"
Application.ScreenUpdating = True
End Sub
Given that you have 100,000 cells to analyze, I made some modifications to reduce run time for the code I posted. This version places the overall average in C1, and starting in C2:D2 the number of data points in a set (col C) and the average value for the set (col D). A test of 100,000 random values which contained 24,995 sets ran in less than 0.2 seconds on a relatively slow processor.
Code:
Sub DataAnalysis()
Dim lR As Long, V As Variant, Avg As Double, ct As Long, Savg As Double
Dim n As Long, S As Double, ctS As Long, Vout As Variant
lR = Range("A" & Rows.Count).End(xlUp).Row
V = Range("A1:A" & lR).Value
ReDim Vout(1 To UBound(V, 1), 1 To 2)
Avg = WorksheetFunction.Average(Range("A1:A" & lR))
Application.ScreenUpdating = False
Columns("C:D").ClearContents
[C1] = Avg
n = 1
NextSet:
Do
       For i = n To UBound(V, 1)
              If V(i, 1) > Avg Then
                     ct = ct + 1
                     n = i + 1
                     S = S + V(i, 1)
              ElseIf ct = 0 Then
                     n = n + 1
                     GoTo NextSet
              Else
                     Exit Do
              End If
       Next i
Loop While n <= UBound(V, 1)
If ct > 0 Then
       ctS = ctS + 1
       Vout(ctS, 1) = ct
       Vout(ctS, 2) = S / ct
       ct = 0
       S = 0
       If n < UBound(V, 1) Then GoTo NextSet
End If
Range("C2:D" & ctS + 1).Value = Vout
MsgBox ctS & " sets analyzed"
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,329
Messages
6,124,301
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top