Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Convert frequency vector to logical matrix

$
0
0

I would like to convert a frequency vector (i.e. the colSums() of a matrix) to one of the possible versions of the original logical matrix in R.

Something like:

    s <- c(1,2,3)
    # Some function of s
    # Example output:
         [,1] [,2] [,3]
    [1,]    0    0    1
    [2,]    1    0    0 
    [3,]    0    1    0
    [4,]    0    0    1
    [5,]    0    0    1
    [6,]    0    1    0

The order of rows is not important. Could someone give me a hint on how to do this?


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>