| To: | s-news@utstat.toronto.edu |
|---|---|
| Subject: | Summary: how to generate the sequence |
| From: | Ning Li <lin@cryptic.rch.unimelb.edu.au> |
| Date: | Tue, 27 Mar 2001 15:17:45 +1000 |
|
~ ~ ~ ~ ~ ~ ~ extract of the original query: ~ ~ ~ ~ ~ ~ ~ I have a variable id looks like this: [1] 920006 920006 920006 920006 920006 920006 [7] 920009 920009 920009 920009 920009 920009 [13] 920020 920020 920020 920020 920020 920020 How to generate a corresponding variable, dumyid, as 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Dear lister, I would like to thank S.D.Byers, Charles E. Wright, Bill Venerables, John Maindonald, Nick Ellis, Briand D. Ripley, Piotrovskij Vladimir, Bjarke Klein and many more, for helping me in finding a solution to the above question. There are two types of solutions. One is to directly generate the sequence using -rep()- : -sort(rep(c(1:n),k))- or -rep(1:n, each=k)- where n=the number of unique id, k=the number of repeated measurement for each id. An alternative is to use -factor- on the original id variable. This works because factors are internally recorded as integers. -codes(factor(id))- or -as.numeric(factor(id))- or -as.numerical(as.factor(id))- The command -unclass(factor(id))- also generates integer indexes of the categories, but it returns the original attributes as well. So it doesn't quite fit in this the case. Especially the -seq()- command which I had been trying on doesn't work at all here. Best Regards Ning Li Research Assistant, CEBU Univ. of Melbourne |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Summary: batch jobs in PC?, Ning Li |
|---|---|
| Next by Date: | Jackknifing, Helen Creegan {PG} |
| Previous by Thread: | Summary: batch jobs in PC?, Ning Li |
| Next by Thread: | Re: Summary: how to generate the sequence, David Scott |
| Indexes: | [Date] [Thread] [Top] [All Lists] |