LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default median of combinations from values in a column

Hi,

I posted this already he

http://groups.google.com/group/micro...35 7c7d62558d

and received some good solutions. However, my original problem has
become a bit more complicated.

Here's the original problem:

I'm trying to figure out how to generate all combinations from a list
of N values in a column, let's say column A.

In particular, I want to have all combinations of 2 values, 3 values,
4, ... up to 7 values.

To give an example: Let's assume I have a list of only 3 values
(1,2,3) for which I want to have all combinations of two values. In
this case, the result would be 1,2; 1,3; and 2;3. The ordering of the
values does not matter, i.e. duplicates should be eliminated.

Now, the extension is that I need the median of each combination
rather than the combinations themselves. So it would be nice if the
code would already calculate the median.

Besides the solution in the link, I also found another code that works
well - but still does not provide me with the median (see below).

An additional problem is the limitation in the number of rows in
excel. Thus, it would be great to have the output in a txt file or
something similar, which may ideally be imported to SPSS.

Any suggestions? Thanks in advance,
Andreas

Sub test()
ListCombos Range("A1:A5"), 3, 7
End Sub

Sub ListCombos(r As Range, m As Long, iRow As Long)
' lists the combinations of r choose m starting in row iRow
Dim ai() As Long
Dim i As Long
Dim n As Long
Dim vOut As Variant

n = r.Rows.Count

Redim ai(1 To m)
Redim vOut(1 To m)

ai(1) = 0
For i = 2 To m
ai(i) = i
Next i

Do
For i = 1 To m - 1
If ai(i) + 1 < ai(i + 1) Then
ai(i) = ai(i) + 1
Exit For
Else
ai(i) = i
End If
Next i
If i = m Then
If ai(m) < n Then
ai(m) = ai(m) + 1
Else
Exit Sub
End If
End If

' put the values in the variant
For i = 1 To m
vOut(i) = r(ai(i))
Next i
' list it
Cells(iRow, 1).Resize(, m).Value = vOut
iRow = iRow + 1
Loop
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
find for non zero values in a column Median,Mode,STDEV Billp Excel Worksheet Functions 2 June 24th 09 03:20 PM
Find the median 3 values Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 6 November 20th 07 07:13 PM
How to display graph if only mean, SD & median values available? A Renshaw Charts and Charting in Excel 2 November 3rd 06 04:24 PM
Counting values lower then the median. [email protected] Excel Worksheet Functions 4 April 18th 06 09:14 PM
Median ignoring Zero Values tlosgyl3 Excel Worksheet Functions 4 October 13th 05 09:14 PM


All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"