BEST way in R to adapt this vector?
Goal:
Suppose you have a vector that is a discrete variable with values
ranging from 1 to 3, and length of 10. We'll use this as the example:
y <- c(1,2,3,1,2,3,1,2,3,1)
...and suppose you want your new vector (y.new) to be equal in length to
the p
Thanks for the help, I've a few more functions to get familiar with. Those
are definitely concise ways to do this! :)
--
View this message in context:
http://www.nabble.com/What%27s-the-BEST-way-in-R-to-adapt-this-vector--tp20638991p20647978.html
Sent from the R help mailing list archive at Nab
Sorry, you wanted a vector not a matrix.
Here are several possibilities. (If you are
willing to hard code the levels then they
can be shortened by replacing sort(unique(y))
or levels(factor(y)) with its value -- in this
case 1:3)
c(outer(sort(unique(y)), y, "=="))+0
c(outer(levels(factor(y)), y,
On Sat, 22 Nov 2008 10:00:18 -0800 (PST)
zerfetzen <[EMAIL PROTECTED]> wrote:
> Goal:
> Suppose you have a vector that is a discrete variable with values
> ranging from 1 to 3, and length of 10. We'll use this as the example:
>
> y <- c(1,2,3,1,2,3,1,2,3,1)
>
> ...and suppose you want your new
Try this:
outer(y, sort(unique(y)), "==")+0
On Sat, Nov 22, 2008 at 3:37 PM, zerfetzen <[EMAIL PROTECTED]> wrote:
>
> Goal:
> Suppose you have a vector that is a discrete variable with values ranging
> from 1 to 3, and length of 10. We'll use this as the example:
>
> y <- c(1,2,3,1,2,3,1,2,3,1)
On Sat, Nov 22, 2008 at 12:00 PM, zerfetzen <[EMAIL PROTECTED]> wrote:
>
> Goal:
> Suppose you have a vector that is a discrete variable with values ranging
> from 1 to 3, and length of 10. We'll use this as the example:
>
> y <- c(1,2,3,1,2,3,1,2,3,1)
>
> ...and suppose you want your new vector (
Goal:
Suppose you have a vector that is a discrete variable with values ranging
from 1 to 3, and length of 10. We'll use this as the example:
y <- c(1,2,3,1,2,3,1,2,3,1)
...and suppose you want your new vector (y.new) to be equal in length to the
possible discrete values (3) times the length (1
7 matches
Mail list logo