In order to operate with strings in R, you need library stringr for that purpose, so the very first line in your code should be:
library("stringr")
R provides a lot of functions for string manipulations.
Purpose of function word is to retrieve word from string based on index of that particular word.
word(a, b)
- a is string that we are going to search through
- b is index of word in string a we want to retrieve as result
Function str_length is going to return length of provided string.
str_length(a)
- a is string that we want to receive length as result
Function str_locate is going to return beginning and ending index of word provided as second argument.
str_locate(a, b)
- a is string that we want to search through.
- b is word we want to look for.
- result of this function is array of two numbers; one for the beginning index of word b and second is ending index of word b.
Purpose of function str_sub is to return substring.
str_sub(a, b, d)
- a is string we want to search through for the substring.
- b is staring index of substring we want to receive as result.
- d in ending index of substring we want to receive as result.
Function str_count is going to return number of occurrences of word we are searching for.
str_count(a, b)
- a is string we want to search through.
- b is string that we want to search for occurrences.
Function str_to_upper is going to return string with all upper letters.
str_to_upper(a)
- a is string that we want to turn all of letters into upper letters. String with all upper letters is going to be provided as result of this function.
Function str_split is going to split provided string by splitting pattern.
str_split(a, b)
- a is string we want to split
- b is splitting patter written in regular expression.
Function str_c is going to add two strings together.
str_c(a, b, sep="")
- a is string that is going to be appended to.
- b is appending string.
- sep is string that is going to be inserted in between a and b.
Function str_remove is going to remove substring from main string.
str_remove(a, b)
- a is string that is going to be removed from.
- b i string that is going to be removed.
Both functions str_replace and str_replace_all are going to replace substrings from main string. First of those two is going to replace only the first occurrence of substring, and second is going to replace every occurrence of substring.
str_replace(a, b, d)
str_replace_all(a, b, d)
- a i string that is going to be replaced from.
- b is string for replacement that is a substring of string a.
- d is string that is going to replace substring b in string a.
For video tutorial, check the link below.
No comments:
Post a Comment