Course
Data Frames
Convert a List to a DataframeCreate an Empty DataframeCombine Two Dataframe into OneChange Column Name of a DataframeExtract Columns From a DataframeDrop Columns in a DataframeReorder Columns in a DataframeSplit DataframeMerge Multiple DataframesDelete Rows From DataframeMake a List of DataframesIntroduction
"Hello World" ProgramAdd Two VectorsFind Sum, Mean and Product of Vector in R ProgrammingTake Input From UserGenerate Random Number from Standard DistributionsSample from a PopulationFind Minimum and MaximumSort a VectorStrings
Concatenate Two StringsFind the Length of a StringCheck if Characters are Present in a StringExtract n Characters From a StringReplace Characters in a StringCompare two StringsConvert Factors to CharactersTrim Leading and Trailing WhitespacesVectors
Concatenate a Vector of StringsCheck if a Vector Contains the Given ElementCount the Number of Elements in a VectorFind Index of an Element in a VectorAccess Values in a VectorAdd Leading Zeros to VectorR Program to Check if Characters are Present in a String
In R, we use the grepl()
function to check if characters are present in a string or not. And the method returns a Boolean value,
TRUE
- if the specified sequence of characters are present in the stringFALSE
- if the specified sequence of characters are not present in the string
Example: Check if Character is Present in a String in R
string1 <- "Programiz"
value1 <- "miz"
# check if "miz" is present in "Programiz"
grepl(value1, string1) # TRUE
value2 <- "grm"
# check if "grm" is present in "Programiz"
grepl(value2, string1) # FALSE
Output
[1] TRUE
[2] FALSE
In the above example, we have used the grepl()
function to check if a sequence of characters is present in a string or not. Notice the code,
grepl(value1, string1)
Here, grepl()
takes two arguments
- value1 - sequence of characters to be searched
- string1 - a string in which value1 is searched
Similarly, value2 is searched in string1
.
Since
"miz"
is present in"Programiz"
, the function returnsTRUE
"grm"
is not present in"Programiz"
, the function returnsFALSE