Search
 
SCRIPT & CODE EXAMPLE
 

R

R get specific character from string

string_var = "this is an example"

# substr(string, first_char_pos, last_char_pos) # extracts characters from pos1 to pos2
substr(x, 1, 3)		# Extract first three characters
# "thi"
substr(x, 4, 4)		# Extract only the fourth character
# "s"

n_last <- 3			# Specify number of characters to extract
# nchar(x) counts total no. of characters in the string
substr(x, nchar(x) - n_last + 1, nchar(x)) 	# Extract last three characters
# "ple"
Comment

PREVIOUS NEXT
Code Example
R :: calculate correlation in r 
R :: how to read in a text file in r 
R :: libpath r 
R :: r create a vector 
R :: r - reorder columns in data frame 
R :: convert string to lowercase R 
R :: r suppress package loading messages 
R :: lubridate sequence of dates 
R :: how to throw an error in R 
R :: r remove insignificant coefficient in output 
R :: make gif r 
R :: extract coefficients from lm in r 
R :: combine ro columns in r 
R :: summary metrics of confusion matrix 
R :: How to extract NA´s from a column? in R 
R :: rstudio 
R :: r code mutate 
R :: st_combine by variables R 
R :: pairing in r 
R :: SSL certificate problem in R 
R :: barplot_density 
Rust :: get random enum rust 
Rust :: rust sum vector 
Rust :: rust how to access elements of an array 
Rust :: rust in a string, replace multiple spaces with single space 
Rust :: armanriazi•rust•pattern•design•interior•mutability 
Rust :: armanriazi•rust•static•vs•cons 
Rust :: rust using regex in if statement 
Rust :: armanriazi•rust•comparison•iter•vs•for 
Rust :: char is digit rust 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =