Community Server

The platform that enables you to build rich, interactive communities
Welcome to Community Server Sign in | Join | Help
in Search

Creating a full data vector using vectors of unique values and frequency weights

Last post 05-28-2007, 11:41 AM by bob_cyz. 2 replies.
Sort Posts: Previous Next
  •  05-27-2007, 10:44 AM 36

    Creating a full data vector using vectors of unique values and frequency weights

    Here's another.

    I want to make a Vector called C with all possibe data values in it. I have a vector A of the -unique- values and and vector B of the frequency of each of the values.  A and B are the same size.

    Example  If  vector A: ( 1  2 3 4 5)  vector B( 1 1 3 4 1) then vector C should be (1 2 3 3 3 4 4 4 4 5)

    Any easy way to do it?

     

  •  05-27-2007, 12:07 PM 37 in reply to 36

    Re: Creating a full data vector using vectors of unique values and frequency weights

    What you are asking for is a generalization of the "SET" command and the "COPY vec1#vec2 result" command. Here you go:

    'Subroutine copies each element from the values vector
    'into the result vector as many times as specified
    'by the element in the same position in the frequencies
    'vector.
    NEWCMD EXPAND values frequencies result
       CLEAR result
       SIZE values valCount
       COPY 1 pos
       WHILE pos <= valCount
          TAKE values  pos val
          TAKE frequencies pos freq
          COPY freq#val valList
          COPY result valList result
          ADD 1 pos pos
       END
    END


    Here's an example program using your vectors:


    COPY ( 1 2 3 4 5) vals
    COPY ( 1 1 3 4 1) freqs
    EXPAND vals freqs result
    PRINT result

    Here's the output:


    result: (1.0 2.0 3.0 3.0 3.0 4.0 4.0 4.0 4.0 5.0)

    John
  •  05-28-2007, 11:41 AM 38 in reply to 37

    Re: Creating a full data vector using vectors of unique values and frequency weights

    I tried "Expand" out and it worked great.  Thanks again. I sent a donation under a different name.

     

    I have found Statistics101 to be a most useful and easy to use program.  I have used it to estimate probabilities, condidence intervals,  and many other statistics.  It is especially useful  for problems with unusual distributions or sparse data or difficult mathematics. I recommend it.

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems