Skip to content
Prev 394023 / 398498 Next

Simple Stacking of Two Columns

Hi,

You were on the right track using stack(), but you just pass the entire data frame as a single object, not the separate columns:
? values ? ind
1 ? ?Tom Name1
2 ? Dick Name1
3 ?Larry Name2
4 ?Curly Name2

Note that stack also returns the index (second column of 'ind' values), which tells you which column in the source data frame the stacked values originated from.

Thus, if you just want the actual data:
[1] "Tom" ? "Dick" ?"Larry" "Curly"

returns a vector, or:
? values
1 ? ?Tom
2 ? Dick
3 ?Larry
4 ?Curly

which returns a data frame with a single column named 'values'.

Regards,

Marc Schwartz
On April 3, 2023 at 11:08:59 AM, Sparks, John (jspark4 at uic.edu (mailto:jspark4 at uic.edu)) wrote: