Skip to content
Prev 374389 / 398530 Next

how can I convert a long to wide matrix?

Hi Marna,
I think this is due to having three rows for id_X and only two for
id_Y. The function creates a data frame with enough columns to hold
the greatest number of values for each ID variable. Notice that the
SITE_n columns contain three values for id_X (A, A, B) and two for
id_Y (A, B, NA) as there was no third occasion of measurement for the
latter. Even though there are only two _values_ for SITE, there must
be enough space for three. In your desired output, SITE for the second
occasion of measurement is wrong (it should be "A"), and for the third
occasion it is unknown. Even if there was only one value for SITE in
the original data frame, it should be repeated for the correct number
of observations. I think you may be mixing up case ID with location of
observation.

Jim
On Wed, May 2, 2018 at 8:48 AM, Marna Wagley <marna.wagley at gmail.com> wrote: