Ask Your Question
3

What is the frequency of a certain value occurring in a vector based on specific conditions in R?

asked 2023-06-06 21:30:53 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-06 21:51:01 +0000

bukephalos gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-06 21:30:53 +0000

Seen: 1 times

Last updated: Jun 06 '23