Skip to content

Instantly share code, notes, and snippets.

@ozjimbob
Created March 6, 2020 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozjimbob/4abcf9999b9460b671385e83249355cd to your computer and use it in GitHub Desktop.
Save ozjimbob/4abcf9999b9460b671385e83249355cd to your computer and use it in GitHub Desktop.
# Simple tibble
d <- tibble(a1="foo",
a2="bar")
# Want to make a new column called "new" and unite all the "a*" columns together
newcol <- "new"
startchar <- "a"
unite(d,col=newcol,starts_with(startchar)) # Yay
# But what if we want to choose the column name from a vector?
newcol <- c("new","something_else")
unite(d,col=newcol[1],starts_with(startchar)) # Nope
# unite(col..) says it wants a "string" as the name of the new column
# How is the first element of a vector with strings in it not a string?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment