Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-20-2012 09:02 AM

Hi all

I have a quick question and I have been struggling for several days. I hope you could help me. Many thanks.

I hope to design a vector as follows: suppose there are two given vector a=[2 3 5], b=[1 2 3]

Here b indicates the frequency vector. I hope to generate a vector c=[2 3 3 5 5 5]. I am trying to use the repeat function in IML, but there is always something wrong

Thanks

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-20-2012 10:01 AM

Use the CUSUM function to get the indexes into a long vector that has sum(b) elements. Loop over the categories and use the REPEAT functions to fill up the vector:

proc iml;

a = {2 3 5};

b = {1 2 3};

cumFreq = 0 || cusum(b);

N = ncol(a);

v = j(sum(b), 1);

do i = 1 to N;

bIdx = 1 + cumFreq*; /* begin index */*

eIdx = cumFreq[i+1]; /* end index */

print i bIdx eIdx;

v[bIdx:eIdx] = repeat(a*, b );*

end;

print v;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-20-2012 11:02 AM

Hi Rick

Many thanks. This is great ! And the function cusum( ) is extremely helpful !