To find the frequency of a certain value occurring in a vector based on specific conditions in R, you can use the table()
function.
For example, if you have a vector x
and you want to find the frequency of the value 5 occurring only when the value of another vector y
is greater than 3, you can use the following code:
table(x[y > 3] == 5)
This will return a table that shows the frequency of TRUE
(meaning the condition is met and the value is 5) and FALSE
(meaning the condition is not met and the value is not 5) in your vector.
Asked: 2023-06-06 21:30:53 +0000
Seen: 1 times
Last updated: Jun 06 '23