0
$\begingroup$

If there is a data set in R and I want know how many of one value is in it, is there a command for this? thanks

$\endgroup$
1
$\begingroup$

If the values are discrete, you can just use

summary(factor(x))

If you just want to know how often a specific value occurs, then the snippet

sum(x==v)

works quite nicely. Beware of NAs, however (e.g. using na.rm=T).

If the value is not discrete, then the notion of "frequency" becomes somewhat ill-defined. The above approach would still work, but I would be very cautious about interpreting the results.

$\endgroup$
1
  • 2
    $\begingroup$ table(x) is often helpful as an alternative $\endgroup$
    – Henry
    Apr 8 '20 at 10:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.