Last active
March 2, 2018 19:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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