[R] Simple Stacking of Two Columns

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Mon Apr 3 18:26:10 CEST 2023


On April 3, 2023 8:08:59 AM PDT, "Sparks, John" <jspark4 using uic.edu> wrote:
>Hi R-Helpers,
>Sorry to bother you, but I have a simple task that I can't figure out how to do.
>For example, I have some names in two columns
>and I simply want to get a single column
>> NamesLong
>  Names
>1   Tom
>2  Dick
>3 Larry
>4 Curly
>Stack produces an error
>Error in if (drop) { : argument is of length zero
>So does bind_rows
>> NamesLong<-dplyr::bind_rows(NamesWide$Name1,NamesWide$Name2)
>Error in `dplyr::bind_rows()`:
>! Argument 1 must be a data frame or a named atomic vector.
>Run `rlang::last_error()` to see where the error occurred.
>I tried making separate dataframes to get around the error in bind_rows but it puts the data in two different columns
>> NamesLong
>  c..Tom....Dick.. c..Larry....Curly..
>1              Tom                <NA>
>2             Dick                <NA>
>3             <NA>               Larry
>4             <NA>               Curly
>gather makes no change to the data
>> NamesLong
>  Name1 Name2
>1   Tom Larry
>2  Dick Curly
>Please help me solve what should be a very simple problem.
>John Sparks
>	[[alternative HTML version deleted]]
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

Sent from my phone. Please excuse my brevity.

More information about the R-help mailing list