Using tabulate () with decimal numbers

I have a vector

a<- c(0.2849579, 0.2849579, 0.2849579)

I would like to use:

tabulate(a,nbins=max(a))

but it returns integer(0)as output.

Can I use tables for decimal numbers?

+1
source share
2 answers

Here are some random numbers replicated

x = sample(runif(10), 1000, TRUE)

Find unique values ​​(optional, round to significant digits), then find the index of each xin the unique values ​​table and place these

## x = signif(x, 6)
ux = sort(unique(x))
idx = match(x, ux)
n = tabulate(idx, nbins=length(ux))

finally summarize the results

df = data.frame(x=ux, n=n)

Use the summary to see all the values.

> head(df)
           x   n
1 0.02832152 108
2 0.04973473  90
3 0.19770913  96
4 0.31591234 103
5 0.59334322  97
6 0.64145901  98

or determine the values ​​with the maximum number of samples

> df[df$n ==  max(df$n), , drop=FALSE]
           x   n
10 0.9711141 127
+1
source

nbins , . max(a) = 0.2849579 , .

tabulate ( ?tabulate) :

"bin" , , .

, tabulate. hist - .

0

Source: https://habr.com/ru/post/1544953/


All Articles