[R] is there an inverse method for table()?
Ravi Varadhan
rvaradhan at jhmi.edu
Tue Mar 9 17:02:28 CET 2010
z <- rep(x, each = y)
Hope this helps,
Ravi.
____________________________________________________________________
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University
Ph. (410) 502-2619
email: rvaradhan at jhmi.edu
----- Original Message -----
From: vincent laperriere <vincent_laperriere at yahoo.fr>
Date: Tuesday, March 9, 2010 10:59 am
Subject: [R] is there an inverse method for table()?
To: r-help at r-project.org
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list
>
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list