Message-ID: <d306a594-f8e4-4d4d-ae04-2c3f11df8979@g1g2000pra.googlegroups.com>
Date: 2008-12-15T02:19:15Z
From: Andrew
Subject: how to create duplicated ID in multi-records per subject dataset
In-Reply-To: <4946540D.5201.00C9.0@efs.mq.edu.au>
if the records are in the file dupIDs.txt, then when you read them in,
the IDs become factors. Coercing them to numeric gets them to assign
a unique number to each factor.
So, you could try the following:
dupIDs <- read.table("dupIDs.txt", header = T)
dupIDs$ID2 <- cummax(as.numeric(dupIDs$ID)-1)
> dupIDs
ID record ID2
1 1 20 1
2 . 30 1
3 . 25 1
4 2 26 2
5 . 15 2
6 3 21 3
HTH,
Andrew.
On Dec 15, 12:56?pm, "Zhixin Liu" <z... at efs.mq.edu.au> wrote:
> Hi R helpers,
>
> If I have a dataset looks like:
> ID ? record
> 1 ? ? ? ?20
> . ? ? ? ? 30
> . ? ? ? ? 25
> 2 ? ? ? ? 26
> . ? ? ? ? 15
> 3 ? ? ? ? 21
> 4.....................
>
> And I want it becomes
> ID ? record
> 1 ? ? ? ?20
> 1 ? ? ? ?30
> 1 ? ? ? ?25
> 2 ? ? ? ? 26
> 2 ? ? ? ?15
> 3 ? ? ? ? 21
> 4.....................
>
> That is, I have to duplicate IDs for those with multiple records. I am wondering it is possible to be done in R, and I am grateful if you would like to show me the direction.
>
> Many thanks!
>
> Zhixin
>
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.