[R] is there an inverse method for table()?

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Tue Mar 9 17:02:34 CET 2010


rep() is your friend.

HTH,

Thierry

> x <- c(86,  90,  94,  98, 102, 106, 110, 114, 118, 122, 126, 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170, 174)
> y <- c(2, 5, 10, 17, 26, 60, 94, 128, 137, 128, 77, 68, 65, 60, 51, 26, 17, 9, 5, 2, 3, 7, 3)
> rep(x, y)
   [1]  86  86  90  90  90  90  90  94  94  94  94  94  94  94  94  94  94  98
  [19]  98  98  98  98  98  98  98  98  98  98  98  98  98  98  98  98 102 102
  [37] 102 102 102 102 102 102 102 102 102 102 102 102 102 102 102 102 102 102
  [55] 102 102 102 102 102 102 106 106 106 106 106 106 106 106 106 106 106 106
  [73] 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106
  [91] 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106
 [109] 106 106 106 106 106 106 106 106 106 106 106 106 110 110 110 110 110 110
 [127] 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110
 [145] 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110
 [163] 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110
 [181] 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110
 [199] 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 114 114
 [217] 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114
 [235] 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114
 [253] 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114
 [271] 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114
 [289] 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114
 [307] 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114
 [325] 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114
 [343] 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
 [361] 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
 [379] 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
 [397] 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
 [415] 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
 [433] 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
 [451] 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
 [469] 118 118 118 118 118 118 118 118 118 118 118 122 122 122 122 122 122 122
 [487] 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122
 [505] 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122
 [523] 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122
 [541] 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122
 [559] 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122
 [577] 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122 122
 [595] 122 122 122 122 122 122 122 122 122 122 122 122 122 126 126 126 126 126
 [613] 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126
 [631] 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126
 [649] 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126
 [667] 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126
 [685] 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130
 [703] 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130
 [721] 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130 130
 [739] 130 130 130 130 130 130 130 130 130 130 130 130 130 130 134 134 134 134
 [757] 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134
 [775] 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134
 [793] 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134 134
 [811] 134 134 134 134 134 134 134 138 138 138 138 138 138 138 138 138 138 138
 [829] 138 138 138 138 138 138 138 138 138 138 138 138 138 138 138 138 138 138
 [847] 138 138 138 138 138 138 138 138 138 138 138 138 138 138 138 138 138 138
 [865] 138 138 138 138 138 138 138 138 138 138 138 138 138 142 142 142 142 142
 [883] 142 142 142 142 142 142 142 142 142 142 142 142 142 142 142 142 142 142
 [901] 142 142 142 142 142 142 142 142 142 142 142 142 142 142 142 142 142 142
 [919] 142 142 142 142 142 142 142 142 142 142 146 146 146 146 146 146 146 146
 [937] 146 146 146 146 146 146 146 146 146 146 146 146 146 146 146 146 146 146
 [955] 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 154
 [973] 154 154 154 154 154 154 154 154 158 158 158 158 158 162 162 166 166 166
 [991] 170 170 170 170 170 170 170 174 174 174

----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
  

> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op r-project.org 
> [mailto:r-help-bounces op r-project.org] Namens vincent laperriere
> Verzonden: dinsdag 9 maart 2010 16:58
> Aan: r-help op r-project.org
> Onderwerp: [R] is there an inverse method for table()?
> 
> Hi,
> 
> In R, I know the method table(), which builds a contingency 
> table of the counts y at each level for the factor x.
> But I would like to know what is the inverse method of 
> table(), if it exists, to obtain the vector z, from the two 
> vectors x and y?
> 
> x <- (86,  90,  94,  98, 102, 106, 110, 114, 118, 122, 126, 
> 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170, 174)
> y <- c(2, 5, 10, 17, 26, 60, 94, 128, 137, 128, 77, 68, 65, 
> 60, 51, 26, 17, 9, 5, 2, 3, 7, 3)
> 
> > z
>    [1]  86  86  90  90  90  90  90  94  94  94  94  94  94  
> 94  94  94  94  98  98  98  98  98  98  98  98  98  98  98  
> 98  98  98  98  98  98 102 102 102 102 102
>   [40] 102 102 102 102 102 102 102 102 102 102 102 102 102 
> 102 102 102 102 102 102 102 102... 
>   [976] ...170 170 170 170 170 170 170 174 174 174
> 
> If such a method does not exist, what code should I type to 
> obtain the complete series quickly?
> 
> Thank you for your help.
> I use version 2.10-1 2009-08-24 for Mac OS.
> 
> Vincent Laperrière.
> 
> 
>       
> 	[[alternative HTML version deleted]]
> 
> 

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.



More information about the R-help mailing list