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 Find Index of an Element in a Vector
Example 1: Find Index Value of R Vector Element Using match()
# create two strings
vowel_letters <- c("a", "e", "i", "o", "u")
# find index value of "i"
match("i", vowel_letters) # 3
# find index value of "u"
match("u", vowel_letters) # 5
Output
[1] 3
[1] 5
In the above example, we have used the match()
function to find the index of an element in the vector named vowel_letters.
Here,
"i"
is present in vowel_letters at the 3rd index, so the method returns 3"u"
is present in vowel_letters at the 5th index, so the method returns 5
Example 2: Find Index Value of R Vector Element Using which()
# create two strings
languages <- c("R", "Swift", "Java", "Python")
# find index value of "Swift" using which()
which(languages == "Swift") # 2
# find index value of "Python" using which()
which(languages == "Python") # 4
Output
[1] 2
[2] 4
Here, we have used the which()
function to find the index value of an element.
Since,
"Swift"
is present in languages at the 2nd index, so the method returns 2"Python"
is present in languages at the 4th index, so the method returns 4