To find the element with the minimum number of occurrences in a list in R, you can use the table function to count the occurrences.
In this example,
data
with several integer elements.table
function to count the occurrences of each element.which.min
function on the table of counts.data <- c(1, 2, 2, 3, 3, 3, 4)
count <- table(data)
least_common <- as.numeric(names(count)[which.min(count)])
cat('Element with the minimum occurrences is:', least_common, '\n')
Element with the minimum occurrences is: 1
In this example,
words
with several string elements.table
function to count the occurrences of each element.which.min
function on the table of counts.words <- c('apple', 'banana', 'apple', 'orange', 'banana', 'apple')
count <- table(words)
least_common <- names(count)[which.min(count)]
cat('Element with the minimum occurrences is:', least_common, '\n')
Element with the minimum occurrences is: orange
In this tutorial, we learned How to find the Element with Minimum Number of Occurrences in a List in R language with well detailed examples.