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
bEST is up to you to define. Here is one simple way
y.new - c(t(model.matrix(~factor(y)-1)))
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of zerfetzen
Sent: Saturday, November 22, 2008 12:00 PM
To: r-help@r-project.org
Subject: [R] What's the BEST way
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
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 (y.new) to
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)
...and
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 vector
6 matches
Mail list logo