[R] is there an inverse method for table()?
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Tue Mar 9 17:03:22 CET 2010
On Tue, Mar 9, 2010 at 3:58 PM, vincent laperriere
<vincent_laperriere at yahoo.fr> wrote:
> 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?
>
rep(x,y)?
repeats each element in x the number of times in y. Looks about right.
Barry
More information about the R-help
mailing list