This is not really a "renumbering" and there is no builtin function.
This
is a case where you want to do some special remapping of numbers and you
have to decide what it is in your case. Also use 'dput' to put data in
email since what you sent was not parseable. Also I think the last two
lines of your desired output is incorrect.
Try this:
> x <- read.table(textConnection(" Id Father Mother
+ 123 0 0
+ 124 0 0
+ 125 123 124
+ 126 123 0
+ 127 125 126
+ 128 0 127
+ 130 123 125"), header=TRUE)> # convert to matrix
> x <- as.matrix(x)
> closeAllConnections()
> # map numbers to a new sequence
> allNums <- sort(unique(as.vector(x)))
> # new numbers
> newNums <- seq(0, by=1, length=length(allNums))
> # now remap the numbers
> x[] <- newNums[match(x, allNums)]
>
> x
Id Father Mother
[1,] 1 0 0
[2,] 2 0 0
[3,] 3 1 2
[4,] 4 1 0
[5,] 5 3 4
[6,] 6 0 5
[7,] 7 1 3>
On Sun, Mar 28, 2010 at 4:50 PM, Val <valkremk@gmail.com> wrote:
> HI all,
> Is there a renumbering function in R?
>
> I would like to renumber the following id numbers
>
> *Input file
> *
> Id Father Mother 123 0 0 124 0 0 125 123 124 126 123 0 127 125 126
> 128 0 127 130 123 125
> *Output*
>
> Id Father Mother 1 0 0 2 0 0 3 1 2 4 1 0 5 3 4 6 0 7 7 1 2
> Any help is highly appreciated in Advance
>
> Val K
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
>
http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
[[alternative HTML version deleted]]