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 the Statistical Mode
Example: Find Statistical Model in R
# create a vector of marks1
marks1 <- c(56, 88, 75, 87, 73, 69, 47, 59, 61, 92)
# define mode() function
mode = function() {
# calculate mode of marks1
return(names(sort(-table(marks1)))[1])
}
# call mode() function
mode()
Output
[1] "47"
In the above example, we have created a function named mode()
to calculate the mode of the marks1 vector.
Inside the function, we have used the table()
function to create a categorical representation of data with the variable names and the frequency in the form of a table.
We will sort marks1 in descending order and will return the 1st value from the sorted values.
Finally, we have called the mode()
function and it returned the most common number in marks1 i.e. 47