Skip to content

Instantly share code, notes, and snippets.

@MCMaurer
Last active March 2, 2018 19:21
Show Gist options
  • Save MCMaurer/9ff857a91a509dfb3651d6dafc8e2c13 to your computer and use it in GitHub Desktop.
Save MCMaurer/9ff857a91a509dfb3651d6dafc8e2c13 to your computer and use it in GitHub Desktop.
Simple gsub to get rid of non-numeric characters and then change to a numeric vector
x <- c("scaffold79", "scaffold30", "scaffold304")
new_x <- gsub("[^0-9]", "", x)
numeric_x <- as.numeric(new_x)
# for a data.frame
x <- NULL
x$scaffolds <- c("scaffold79", "scaffold30", "scaffold304")
x$scaffolds <- gsub("[^0-9]", "", x$scaffolds)
x$scaffolds <- as.numeric(x$scaffolds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment