Re: [R] Recode numbers

2011-06-01 Thread Dennis Murphy
Hi: Here's another option: rep(b, rle(a)$lengths) > identical(a1, rep(b, rle(a)$lengths)) [1] TRUE rle(a)$lengths computes a table of the number of consecutive repeats of a number (or run lengths). It will have the same length as b in this case. Using rep() with the table of lengths as repetiti

Re: [R] Recode numbers

2011-06-01 Thread William Dunlap
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Lisa > Sent: Wednesday, June 01, 2011 12:28 PM > To: r-help@r-project.org > Subject: Re: [R] Recode

Re: [R] Recode numbers

2011-06-01 Thread Lisa
Thank you, Duncan, Here “a” has the length of 24, and “b” has the length of 20 with numbers from 1 to 20 uniquely. I just want encode “a” from 1 to 20 based on “a” current order using “b”. So, a1[1] = b[1] = 1 a1[2] = b[2] = 5 a1[3] = a1[4] = b[3] = 8 (since third and fourth numbers are the same i

Re: [R] Recode numbers

2011-06-01 Thread Duncan Murdoch
(The attributions are a little messed up here:) I have two sets of numbers that look like a<- c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3, 4) b<- c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, 19) I just want to use “b” to encode “a” so that “a”

Re: [R] Recode numbers

2011-06-01 Thread Lisa
Thank you for your help, Pete. I tried b[a], but it is not a1. -- View this message in context: http://r.789695.n4.nabble.com/Recode-numbers-tp3566395p3566534.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailin

[R] Recode numbers

2011-06-01 Thread Lisa
Dear all, I have two sets of numbers that look like a <- c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3, 4) b <- c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, 19) I just want to use “b” to encode “a” so that “a” looks like a1<- c(1, 5, 8, 8, 9, 9,

Re: [R] Recode numbers

2011-06-01 Thread Pete Brecknock
Lisa wrote: > > Dear all, > > I have two sets of numbers that look like > > a <- c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, > 3, 4) > > b <- c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, > 19) > > I just want to use “b” to encode “a” so that “a”