Extract First or Last n Characters from String in R (3 Examples) | Get Leading & Trailing Chars

Publicado el: 12 febrero 2022
en el canal de: Statistics Globe
1,316
28

How to extract n leading or trailing characters from a string in the R programming language. More details: https://statisticsglobe.com/r-extract...
R code of this video:

x <- "this is an example" # Create example character string
x # Print example character string

substr(x, 1, 3) # Extract first three characters

n_last <- 3 # Specify number of characters to extract
substr(x, nchar(x) - n_last + 1, nchar(x)) # Extract last three characters

install.packages("stringr") # Install stringr package in R
library("stringr") # Load stringr package

str_sub(x, 1, 3) # Extract last characters with str_sub

str_sub(x, - 3, - 1) # Extract last characters with str_sub

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – Group for Discussions & Questions:   / statisticsglobe  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – Group for Discussions & Questions:   / 12555223  
Twitter:   / joachimschork  

Music by bensound.com


En esta página del sitio puede ver el video en línea Extract First or Last n Characters from String in R (3 Examples) | Get Leading & Trailing Chars de Duración hora minuto segunda en buena calidad , que subió el usuario Statistics Globe 12 febrero 2022, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 1,316 veces y le gustó 28 a los espectadores. Disfruta viendo!