Re: [R] What's the BEST way in R to adapt this vector?

2008-11-23 Thread Jagat.K.Sheth
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

Re: [R] What's the BEST way in R to adapt this vector?

2008-11-23 Thread zerfetzen
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

Re: [R] What's the BEST way in R to adapt this vector?

2008-11-22 Thread Gabor Grothendieck
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,

Re: [R] What's the BEST way in R to adapt this vector?

2008-11-22 Thread Berwin A Turlach
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

Re: [R] What's the BEST way in R to adapt this vector?

2008-11-22 Thread Gabor Grothendieck
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)

Re: [R] What's the BEST way in R to adapt this vector?

2008-11-22 Thread hadley wickham
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 (

[R] What's the BEST way in R to adapt this vector?

2008-11-22 Thread zerfetzen
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