Quantcast
Viewing all articles
Browse latest Browse all 206553

Extract the first 2 Characters in a string

I need to extract the 1st 2 characters in a string to later create bin plot distribution. vector:

x <- c("75 to 79", "80 to 84", "85 to 89") 

I have gotten this far:

substrRight <- function(x, n){
  substr(x, nchar(x)-n, nchar(x))
}

invoke function

substrRight(x, 1)

Response

[1] "79""84""89"

Need to prints the last 2 characters not the first.

[1] "75""80""85"

Viewing all articles
Browse latest Browse all 206553

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>