Skip to content

Instantly share code, notes, and snippets.

@arcaravaggi
Last active August 15, 2017 10:45
Show Gist options
  • Save arcaravaggi/05a1b15fa67a74ba9f0b0614f9a8281c to your computer and use it in GitHub Desktop.
Save arcaravaggi/05a1b15fa67a74ba9f0b0614f9a8281c to your computer and use it in GitHub Desktop.
Split column into multiple based on spaces, extra characters, etc.
# Split column into multiple based on spaces, extra characters, etc.
df <- data.frame(x= c("crust (5)","things (3)","stuff (8)"))
library(tidyr)
df2 <- extract(df, x, into = c("pet", "sampSize"), "([^(]+)\\s+\\(([0-9]+).")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment